【发布时间】:2018-08-23 02:29:53
【问题描述】:
在将我的休息服务从 Spring Boot 1.5.10 升级到 2.0.0 之后,我遇到了我之前通过的测试失败。
以下场景:
import org.mockito.internal.matchers.Null;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
...
.andExpect(jsonPath("img").value(Null.NULL))
现在在 Spring MVC 5 中失败并显示以下消息:
java.lang.AssertionError:JSON 路径“img”
预期:isNull() 实际:null
Spring MVC 5 中断言jsonPath 的值为null 的正确方法是什么?
【问题讨论】:
-
你在使用 jayway lib 的 jsonpath 吗?能否请您显示 jsonpath 的名称包名称?
-
我正在使用
org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -
另一种方法是使用 new JsonPathExpectationsHelper("$.img").assertValueIsEmpty(jsonContent);
标签: spring spring-mvc spring-boot mockito spring-test