How to unittest a class using RestTemplate offline?

后端 未结 4 612
南笙
南笙 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条回答
  •  暖寄归人
    2020-12-29 21:09

    Sping 3.0 introduced RestTemplate. Since version 3.2, the Spring MVC test framework has provided the class MockRestServiceServer for unit testing client REST code.

提交回复
热议问题