【发布时间】:2019-12-20 00:12:39
【问题描述】:
是否可以使用 MockMCV 来比较实际的 ResponseEntity 和从控制器返回的那个?
@Test
public void testStatusGetAllCars() throws Exception {
ResponseEntity<?> expectedResponse = carController.getAllCars();
mockMVC.perform(MockMvcRequestBuilders.get("/api/cars"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/hal+json;charset=UTF-8"))
.andExpect( /// compare goes here // );
}
【问题讨论】:
-
你试过这样的事情吗? stackoverflow.com/questions/18336277/… 您可以将您的预期响应转换为字符串并比较这两个对象,如字符串。
标签: spring-boot httpresponse spring-test mockmvc