How to unittest a class using RestTemplate offline?

后端 未结 4 611
南笙
南笙 2020-12-29 20:09

I have a class which has direct dependency on the RestTemplate. I wish I have a JUnit test of it, offline.

How could I mock a RestTemplate in my unittest?

4条回答
  •  萌比男神i
    2020-12-29 21:04

    spring-social-test contains mockup classes that help write tests for RestTemplate. There are also some examples on how to use it within the git repository (e.g. OAuth1TemplateTest).

    Please keep in mind that there's currently a Spring feature request (#SPR-7951) to move these classes to spring-web.

提交回复
热议问题