7

I have JUnit tests for REST web services. Now I think that JUnit is not the best tool for that, since these tests are integration tests but not unit tests. So I probably need a Java library, which helps to send HTTP requests, verify HTTP responses, create reports and do that in parallel.

On the other hand maybe I am mistaken and Junit (with HTTPUnit etc.) is good enough and I don't need other tools.

What would you suggest?

Michael
  • 41,026
  • 70
  • 193
  • 341

2 Answers2

2

I am also facing similar questions... and am starting looking around and experimenting.

I found this is other stackoverflow question: Unit testing a JAX-RS Web Service? (apparently Jersey allows to make such type of tests).

These are two options that popped up:

Community
  • 1
  • 1
emgsilva
  • 3,047
  • 1
  • 17
  • 16
2

Keep it simple. Have a look at https://github.com/valid4j/http-matchers

// Statically import the library entry point:
import static org.valid4j.matchers.http.HttpResponseMatchers.*;

// Invoke your web service using plain JAX-RS. E.g:
Client client = ClientBuilder.newClient();
Response response = client.target("http://example.org/hello").request("text/plain").get();

// Verify the response
assertThat(response, hasStatus(Status.OK));
assertThat(response, hasHeader("Content-Encoding", equalTo("gzip")));
assertThat(response, hasEntity(equalTo("content")));
// etc...
keyoxy
  • 4,423
  • 2
  • 21
  • 18