我需要验证像下面这样的响应是否包含一些字段。我对字段值不感兴趣 - 只是键存在。例如,我想检查这种类型的响应中是否存在键“id”。我将如何做到这一点?
[
{
"id":"1",
"title":"Title",
"details":"details",
"benefit":"Welcome",
"expirationTimestamp":1549995900,
"notice":"some text",
}
]
如果我做
given()
.spec(reqSpec).
when()
.get().
then()
.body("$", hasKey("id"));
我收到这样的错误:
java.lang.AssertionError: 1 expectation failed.
JSON path $ doesn't match.
Expected: map containing ["id"->ANYTHING]
Actual: [{blabla=something, id=1, details=details, etc=etc}]
拜托,有人可以向我解释这应该如何工作吗?