如果两个jsonPath值相等,我想比较一下:
this.mockMvc.perform(get(requestURL)).andExpect(jsonPath("$.prop1", equalTo(jsonPath("$.prop2"))));但后来我的考试失败了。jsonPath("$.prop1")返回我想要的正确值,但是jsonPath("$.prop2")返回的不是这个属性的值,而是类名:
org.springframework.test.web.servlet.result.JsonPathResultMatchers@7b7aaaf6
有人能告诉我如何为()执行jsonPath() 方法吗?我也尝试过jsonPath("$.prop2").toString(),但也收到了这个类名。
谢谢你的进阶!
发布于 2018-03-28 14:26:02
MvcResult result = this.mockMvc.perform(get(requestURL)).andReturn();
String response = result.getResponse().getContentAsString();
assertEquals(JsonPath.parse(response).read("$.prop1").toString(),JsonPath.parse(response).read("$.prop2").toString());有关更多详细信息,请参阅github自述。
https://stackoverflow.com/questions/49534041
复制相似问题