How to properly unit test RestEasy responses? How to properly unit test RestEasy responses? json json

How to properly unit test RestEasy responses?


I think the question is much subjective and my answer will be also IMO:

  1. I would go such way as well. as for me I saw a lot of times when bug/issue is caught on the implementation level or after server/client REST API migration

  2. There are some duplication - RequestDescriptor, RequestCreator, ClientRequest, ClientResponse. So you could extract some classes to reduce this boilerplate code. Take look to Square Retrofit example https://github.com/square/retrofit/blob/master/retrofit-samples/github-client/src/main/java/com/example/retrofit/GitHubClient.java

  3. Someone could say, that integration tests are more valuable and could be used not as addition but instead of unit tests for REST. But I don't think so. And yes, we are exposing a lot details of the implementation here, it means every change you have to change tests as well

I would probably also convert requests to url and bodies. And use string or JSON comparison for asserts. That would be much less code


For integration tests and to test the resteasy service deployed in a server restassured is the good one.