【发布时间】:2019-08-28 15:13:46
【问题描述】:
我正在使用MockMvc 测试返回 JSON 内容的 API,并且该 JSON 可能包含一个名为 shares 的字段作为空数组,或者可能根本不存在(我的意思是分享字段)。
JSON 示例:
{
"id":1234,
.....
"shares":[]
}
//or
{
"id":1234,
....
}
如何断言该字段为空或不存在
喜欢:
mvc.perform(
post("....url.......")
.andExpect(status().is(200))
// I need one of the following to be true, but this code will assert both of them, so it will fail
.andExpect(jsonPath("$.shares").isEmpty())
.andExpect(jsonPath("$.shares").doesNotExist())
【问题讨论】:
标签: java junit spring-boot-test mockmvc