How to unittest a class using RestTemplate offline?

Dennis C picture Dennis C · Jan 10, 2011 · Viewed 25.4k times · Source

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?

Answer

Raedwald picture Raedwald · Sep 12, 2013

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.