我正在嘗試使用 spring boot 進(jìn)行簡(jiǎn)單的測(cè)試。mockMvc.perform(post("/user")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(userJohn)))
.andExpect(jsonPath("$[0].username", is("bob")));對(duì) jsonPath 使用此導(dǎo)入:import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;我得到:andExpect (org.springframework.test.web.servlet.ResultMatcher) in ResultActions cannot be applied to (org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath)如果我嘗試將其轉(zhuǎn)換為 (ResultMatcher),我會(huì)得到:java.lang.ClassCastException: org.springframework.test.web.servlet.result.JsonPathResultMatchers cannot be cast to org.springframework.test.web.servlet.ResultMatcher我使用的是 Spring Boot 2.0.4 版。有什么想法可能是什么問題?
添加回答
舉報(bào)
0/150
提交
取消