开发者

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 ther开发者_Python百科e.

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.


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");


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.


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.


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.


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.


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 ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜