Ways to test RESTful services? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
开发者_开发知识库Closed 9 years ago.
Improve this questionI want to test my RESTful applications directly via HTTP and I am looking for tools that can help me with that task. Basically I am looking for an easy wrapper for HTTP requests that can submit e.g. HTML forms or serialized resources as JSON or XML.
It would be great if there is a way to verify if the service is actually following REST architectural guidelines (statelessness, URIs, content negotiation etc.), too.
Being able to use it with JUnit would be a convenient bonus. Do you know about any libraries that could help me with what I want to do (and that are a little more than just a simple http client)?
See if rest-client is of any help.
Edit: Currently I am using Postman - REST Client a google chrome plugin and it's awesome!
I think REST Assured will suite you very well. It's very easy to send requests and to parse XML and JSON responses. E.g. let's say that a GET request to "/lotto" returns 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]
}]
}
}
You can make the request and validate the response like this:
expect().body("lotto.lottoId", equalTo(5)).when().get("/lotto");
There is also the Jersey Test Framework (http://jersey.java.net/nonav/documentation/latest/user-guide.html#test-framework) but as Johan already mentioned the REST-assured framework I'd also recommend this framework - it has some nice featues like a DSL like syntax, XPath and Schema validation, easy file upload and using Groovy Lambda Expressions to search through returned JSON structures..
I have written two articles..
- the first one compares REST-assured and Jersey-Test-Framework (http://www.hascode.com/2011/09/rest-assured-vs-jersey-test-framework-testing-your-restful-web-services/),
- the second explores the features of the REST-assured framework against a given REST service (http://www.hascode.com/2011/10/testing-restful-web-services-made-easy-using-the-rest-assured-framework/)
Fiddler is a really useful tool, you can create XML based HTTP Requests with a variety of request verbs like GET,POST,PUT,DELETE and so on.
http://www.fiddler2.com/fiddler2/
Maybe Selenium can be of some help, but surely not entirely.
精彩评论