Zee Spencer
Zee Spencer

Reputation: 3538

Is there a Java Package for testing RESTful APIs?

I'm getting ready to dive into testing of a RESTful service. The majority of our systems are built in Java and Eclipse, so I'm hoping to stay there.

I've already found rest-client (http://code.google.com/p/rest-client/) for doing manual and exploratory testing, but is there a stack of java classes that may make my life easier? I'm using testNG for the test platform, but would love helper libraries that can save me time.

I've found http4e (http://www.ywebb.com/) but I'd really like something FOSS.

Upvotes: 5

Views: 4109

Answers (6)

Camilo Casadiego
Camilo Casadiego

Reputation: 920

I was working today around the unit testing of a rest service, I needed to test the deployed server in order to check some concurrency requeriments, so I needed to test the deployes rest service.

At first I tried the solution sugested by Johan, and started with REST Assured with some succes, but look for more documentation, I found this:

http://uttesh.blogspot.com/2012/09/spring-rest-web-service-test.html

its based on a spring library, so if you are using spring, you'll keep using the stuff from the same vendor, which is always nice.

Also I found the libs from spring easier to understand than REST Assured, but it's just me ;)

Upvotes: 0

Spacemonkey
Spacemonkey

Reputation: 1763

Another informal option to test your REST services is by using the Firefox RESTClient Add-on. Postman REST Client for Google Chrome is another option.

Upvotes: 1

Johan
Johan

Reputation: 40510

You can use REST Assured which makes it very easy to test and validate REST services in Java from JUnit or TestNG. E.g. let's say that a GET request to a service called "/lotto" returns the following JSON

{ "lotto":{ "lottoId":5, "winning-numbers":[2,45,34,23,7,5,3], "winners":[{ "winnerId":23, "numbers":[2,45,34,23,3,5] },{ "winnerId":54, "numbers":[52,3,12,11,18,22] }] } }

then you can make the request and validate the response (in this case that lotto id equal to 5) with REST Assured like this:

expect().body("lotto.lottoId", equalTo(5)).when().get("/lotto");

Upvotes: 10

Zee Spencer
Zee Spencer

Reputation: 3538

Apparently rest-client has a library built in. I'm using that with testNG and XStream and it seems to be exactly what the doctor ordered.

Upvotes: 0

Chris Dolan
Chris Dolan

Reputation: 8963

CXF apparently has support for REST. I haven't tried the REST support yet myself, but I think CXF is a superb, flexible, standards-based webservice implementation.

Upvotes: 1

Rob Tanzola
Rob Tanzola

Reputation: 1795

Would JMeter be an option? It has HTTP Request samplers that support all of the HTTP methods and assertions to validate the response.

Another alternative might be something like soapUI which has an API that could be integrated with your test cases, though I haven't tried it.

Upvotes: 3

Related Questions