Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing a JAX-RS Web Service?

I'm currently looking for ways to create automated tests for a JAX-RS (Java API for RESTful Web Services) based web service.

I basically need a way to send it certain inputs and verify that I get the expected responses. I'd prefer to do this via JUnit, but I'm not sure how that can be achieved.

What approach do you use to test your web-services?

Update: As entzik pointed out, decoupling the web service from the business logic allows me to unit test the business logic. However, I also want to test for the correct HTTP status codes etc.

like image 872
Einar Avatar asked Sep 23 '08 14:09

Einar


People also ask

Is JAX-RS a web services technology?

JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Web Services. Its 2.0 version was released on the 24th May 2013. JAX-RS uses annotations available from Java SE 5 to simplify the development of JAVA based web services creation and deployment.


2 Answers

Jersey comes with a great RESTful client API that makes writing unit tests really easy. See the unit tests in the examples that ship with Jersey. We use this approach to test the REST support in Apache Camel, if you are interested the test cases are here

like image 119
James Strachan Avatar answered Oct 17 '22 19:10

James Strachan


You can try out REST Assured which makes it very simple to test REST services and validating the response in Java (using JUnit or TestNG).

like image 31
Johan Avatar answered Oct 17 '22 19:10

Johan