Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 513
Zee Spencer Avatar asked Apr 13 '10 17:04

Zee Spencer


People also ask

Which Java library can be used for testing API?

When using Java, REST-Assured is my first choice for API automation. In fact, it's the main tool I use for API testing. REST-Assured is a fluent Java library you can use to test HTTP-based REST services. It's designed with testing in mind, and it integrates with any existing Java-based automation framework.


2 Answers

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");
like image 88
Johan Avatar answered Oct 19 '22 03:10

Johan


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.

like image 24
Rob Tanzola Avatar answered Oct 19 '22 04:10

Rob Tanzola