I am trying to test REST
client functionality when the response status indicates error. So I want to mock the rest service to return an error code (like 404) and test that the client is handling the error cases correctly. Is there a way to mock the service?
Try Mockito
It's a nice mocking framework for Java
尝试使用Spring MVC测试支持 。
mockito is a good choice for unit testing. If you are interested in automated integration testing you might wanna try some webservice mocking tool, such as this one: https://sourceforge.net/p/soaprest-mocker
You can set response code and/or response body on mock, execute your request against the mock and verify request(s) that reached the mock.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.