我正在使用 MockMvcResultMatchers 来测试我的 Controller 类。
这是一个示例代码
RequestBuilder request = get("/employee/")
.contentType(MediaType.APPLICATION_JSON)
.accept(APPLICATION_JSON_UTF8);
mockMvc
.perform(request)
.andExpect(status().isOk())
.andExpect(jsonPath("$.total").exists());
但是我如何比较 $.total 值和数字?
我的意思是,有没有办法找出 $.total > 0?
最佳答案
json path value
方法可以将org.hamcrest.Matcher
作为参数。所以你可以使用 GreaterThan
类:
jsonPath("['key']").value(new GreaterThan(1))
这个类来自org.mockito.internal.matchers
包。
关于java - Spring MockMvcResultMatchers jsonPath 低于/大于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32199577/