REST-assured用于方便REST服务测试的JAVADSL。
举例如下:Here'saexampleofhowtomakeaGETrequestadvalidatetheJSONorXMLrespose:
get("/lotto").the().assertThat().body("lotto.lottoId", equalTo(5));Getadverifyallwierids:
get("/lotto").the().assertThat().body("lotto.wiers.wierId", hasItems(23, 54));Usigparameters:
give(). param("key1", "value1"). param("key2", "value2"). whe(). post("/somewhere"). the(). body(cotaisStrig("OK"));UsigX-Path(XMLoly):
give(). parameters("firstName", "Joh", "lastName", "Doe"). whe(). post("/greetMe"). the(). body(hasXPath("/greetig/firstName[text()='Joh']")).Needautheticatio?RESTAssuredprovidesseveralautheticatiomechaisms:
give().auth().basic(userame, password).whe().get("/secured").the().statusCode(200);Gettigadparsigaresposebody:
// Example with JsoPath Strig jso = get("/lotto").asStrig() List<Strig> widerIds = from(jso).get("lotto.wiers.wierId"); // Example with XmlPath Strig xml = post("/shoppig").adRetur().body().asStrig() Node category = from(xml).get("shoppig.category[0]");RESTAssured支持任何HTTP方法,但显式支持POST,GET,PUT,DELETE,OPTIONS,PATCH和HEAD,并且包括轻松指定和验证参数,标头,cookie和主体。
评论