Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library for testing web services

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?

like image 660
Michael Avatar asked Jul 13 '13 10:07

Michael


People also ask

Which tool is used for web service testing?

HttpMaster is a web service tool that exclusively tests REST web services. It is utilized to test behavior of REST APIs and verify data output in formats including XML, JSON and HTML. HttpMaster is a great choice for simulating client activity and response behavior of an API application.

What are the libraries used in selenium Java?

Selenium provides support to multiple libraries such as Ruby, Python, Java, etc as language bindings have been developed by Selenium developers to provide compatibility for multiple languages. For instance, if you want to use the browser driver in Python, use the Python Bindings.


2 Answers

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:

  • https://code.google.com/p/rest-assured/
  • https://code.google.com/p/rest-client/
like image 149
emgsilva Avatar answered Oct 06 '22 03:10

emgsilva


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...
like image 26
keyoxy Avatar answered Oct 06 '22 02:10

keyoxy