【发布时间】:2019-01-04 17:52:03
【问题描述】:
我正在尝试使用 RestAssured 验证此 JSON:
{
"valueBounds": [
{
"bound": {
"min": 1.0,
"max": 4.2
},
"date": "2019-01-04T18:40:28.204+0100"
}
],
}
使用此代码:
given().when().get(rootPath + "/test/").then().statusCode(200).log().body().
body("valueBounds.bound.min", hasItems(1.0));
为什么我得到它们不匹配:
java.lang.AssertionError: 1 expectation failed.
JSON path valueBounds.bound.min doesn't match.
Expected: (a collection containing <1.0>)
Actual: [1.0]
我尝试过使用 Arrays.asList(1.0) 但这不是问题。
【问题讨论】:
-
您正在使用 Hamcrest 匹配器 hasItems()。尝试使用 equalTo() 代替
-
它非常明确地说:期望“一个集合”,但得到一个普通的数字。
标签: java rest-assured