继续来做RestAssured的基本功能练习,
先来看看root()这个方法的使用效果。
1.root()
作用:设置一个body断言开始的base路径,后面boday断言中可以不写完整路径,只写当前路径。
例如,加入这里有这么一个请求的响应是这样。
{
"RestResponse":{
"code" :"0",
"message" :"ok",
"result":{
"name":"静静",
"age" : 18,
"gender": "女"
}
}
}
场景1:不使用root()
@Test
public void testWithoutRoot() {
given().
get("xxxxxxxurlxxxxx").
then().
body("RestResponse.result.name", is("tom")).
body("RestResponse.result.age", is("18")).
body("RestResponse.result.gender", is("man"));
}
场景2:使用root()
@Test
public void testWithoutRoot() {
given().
get("xxxxxxxurlxxxxx").
then().
root("RestResponse.result"). #增加root
body("name", is("tom")).
body(