如何使用 JSON 响应通过 Rest Assured 基于正文项进行断言?

JJB*_*JJB 4 java rest rest-assured web-api-testing rest-assured-jsonpath

如何使用放心的 .body() 方法在“描述”数组中断言我的属性。

例子:

 .body ("[0] .userType", equalTo (1)); // error 
Run Code Online (Sandbox Code Playgroud)

这是我当前想要断言的 JSON 数据:

{
"validSession": true,
"value": "xxx",
"description": [
    {
        "userType": 1,
        "userTypeDescription": "xxx",
        "uname": "xx",
        "distributorId": 1
    }
]}
Run Code Online (Sandbox Code Playgroud)

JJB*_*JJB 7

我编辑了一下:

.body("validSession",is(true))
.body("description[0].userType", equalTo(1))
.body("description[0].userTypeDescription", containsString("xxx"))
.body("description[0].uname", containsString("xx"))
.body("description[0].distributorId", equalTo(1));
Run Code Online (Sandbox Code Playgroud)

我测试过并且有效。但我不明白为什么它只能通过将数组的所有元素的索引为零来工作。

你可以解释吗?