微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

REST-assured

程序名称:REST-assured

授权协议: Apache

操作系统: 跨平台

开发语言: Java

REST-assured 介绍

用于方便REST服务测试的JAVA DSL

举例如下:

Here’s an example of how to make a GET request and validate the JSON or XML
response:

get("/lotto").then().assertthat().body("lotto.lottoId", equalTo(5));

Get and verify all winner ids:

get("/lotto").then().assertthat().body("lotto.winners.winnerId", hasItems(23, 54));

Using parameters:

given(). param("key1", "value1"). param("key2", "value2"). when(). post("/somewhere"). then(). body(containsstring("OK"));

Using X-Path (XML only):

given(). parameters("firstName", "John", "lastName", "Doe"). when(). post("/greetMe"). then(). body(hasXPath("/greeting/firstName[text()='John']")).

Need authentication? REST Assured provides several authentication mechanisms:

given().auth().basic(username, password).when().get("/secured").then().statusCode(200);

Getting and parsing a response body:

// Example with JsonPath 
String json = get("/lotto").asstring() 
List<String> winnderIds = from(json).get("lotto.winners.winnerId"); 
// Example with XmlPath 
String xml = post("/shopping").andReturn().body().asstring() 
Node category = from(xml).get("shopping.category[0]");

REST Assured supports the POST , GET , PUT , DELETE , OPTIONS ,
PATCH and HEAD http methods and includes specifying and validating e.g.
parameters, headers, cookies and body easily.

REST-assured 官网

https://github.com/jayway/rest-assured

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐