REST-assured 方便 REST 服务测试的 JAVA DSL开源项目

我要开发同款
匿名用户2016年02月04日
57阅读
所属分类Java、Web应用开发、REST/RESTful项目
授权协议Apache

作品详情

REST-assured用于方便REST服务测试的JAVADSL。

举例如下:

Here'sanexampleofhowtomakeaGETrequestandvalidatetheJSONorXMLresponse:

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

Getandverifyallwinnerids:

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

Usingparameters:

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

UsingX-Path(XMLonly):

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

Needauthentication?RESTAssuredprovidesseveralauthenticationmechanisms:

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

Gettingandparsingaresponsebody:

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

RESTAssured支持任何HTTP方法,但显式支持POST,GET,PUT,DELETE,OPTIONS,PATCH和HEAD,并且包括轻松指定和验证参数,标头,cookie和主体。

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论