I'm using REST Assured with Hamcrest matchers in my tests:
given()
//...
.assertThat()
.body("id", arrayContaining(job1.getId(), job2.getId()))
.statusCode(200);
After running them I get the following error:
JSON path id doesn't match.
Expected: is [<70a1deec-ce17-4064-8037-5e546d3ed329>, <7ccd5ad0-7425-4df5-be64-bb8584da5d96>]
Actual: <[70a1deec-ce17-4064-8037-5e546d3ed329, 7ccd5ad0-7425-4df5-be64-bb8584da5d96]>
The response has following format:
[
{
"id": "some UUID 1"
"other_properties": ...
},
{
"id": "some UUID 1"
"other_properties": ...
}
]
My question is what triangle brackets mean? And which matcher is better to use. I know I probably just googled it wrong, but I've spent few days by googling and reading documentation and examining code on github. Yet still haven't find explanation about errors format. Thank you
The problem is not the selector, but your matcher.
arrayContainingcan only match against arrays, whilecontainscan match against any kind ofIterable.arrayContaining:contains:So change your assertion to
.body("id", contains(job1.getId(), job2.getId()))and your test should succeed.