我在线搜索但找不到原因或如何修复它。
问题:
我的JUnit测试从REST-API中提取用户ID列表。 但是,我似乎无法断言回复的内容......
API响应:
[
{"userId":1458548702},
{"userId":1458548703},
{"userId":1458548704},
{"userId":1458548706},
{"userId":1458548707}
]
断言代码:
List<Integer> expectedIds = ....
ResultActions result = ...
//JSONArray and expectedIds are the same length
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$.*",
Matchers.hasSize(expectedIds.size())
)
);
//Below Fails:
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$[*].userId",
Matchers.containsInAnyOrder(expectedIds)
)
);
错误讯息:
java.lang.AssertionError: JSON path "$[*].userId"
Expected: iterable over [<[1458548702, 1458548703, 1458548704, 1458548706, 1458548707]>] in any order
but: Not matched: <1458548702>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...
我正在使用的库: