gpt4 book ai didi

java - Spring MockMvcResultMatchers jsonPath 低于/大于

转载 作者:行者123 更新时间:2023-11-29 06:31:45 30 4
gpt4 key购买 nike

我正在使用 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com