Ways to test RESTful services? [closed]

2019-03-09 18:13发布

I 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)?

5条回答
唯我独甜
2楼-- · 2019-03-09 18:36

Maybe Selenium can be of some help, but surely not entirely.

查看更多
做个烂人
3楼-- · 2019-03-09 18:39

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/

查看更多
时光不老,我们不散
4楼-- · 2019-03-09 18:40

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");
查看更多
一夜七次
5楼-- · 2019-03-09 18:45

See if rest-client is of any help.

Edit: Currently I am using Postman - REST Client a google chrome plugin and it's awesome!

查看更多
做自己的国王
6楼-- · 2019-03-09 18:47

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..

查看更多
登录 后发表回答