【发布时间】:2018-10-15 12:42:23
【问题描述】:
我有以下回应:
[
{
"id": 53,
"fileUri": "abc",
"filename": "abc.jpg",
"fileSizeBytes": 578466,
"createdDate": "2018-10-15",
"updatedDate": "2018-10-15"
},
{
"id": 54,
"fileUri": "xyz",
"filename": "xyz.pdf",
"fileSizeBytes": 88170994,
"createdDate": "2018-10-15",
"updatedDate": "2018-10-15"
}
]
我正在尝试将 id 值与 JUnit 中的对象匹配,如下所示:
RestAssured.given() //
.expect() //
.statusCode(HttpStatus.SC_OK) //
.when() //
.get(String.format("%s/%s/file", URL_BASE, id)) //
.then() //
.log().all() //
.body("", hasSize(2)) //
.body("id", hasItems(file1.getId(), file2.getId()));
但是当匹配发生时,它会尝试将int 匹配到long。相反,我得到了这个输出:
java.lang.AssertionError: 1 expectation failed.
JSON path id doesn't match.
Expected: (a collection containing <53L> and a collection containing <54L>)
Actual: [53, 54]
如何告诉 Rest Assured 该值确实很长,即使它可能短到可以放入 int 中?我可以将文件的 id 转换为 int 并且它可以工作,但这似乎很草率。
【问题讨论】:
标签: testing rest-assured rest-assured-jsonpath