我是初级测试的新手。
而且我现在正在尝试测试和删除api,但是找不到andDo(print())。
为了使用此功能,我需要导入什么东西吗?

  @Autowired
  private MockMvc mockMvc;

  @Test
  public void compareDeleteTest() throws Exception{
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("Content-Type", "application/json");

    RequestBuilder requestBuilder = MockMvcRequestBuilders.delete("api/compare/3")
            .headers(httpHeaders);

    MvcResult result = mockMvc.perform(requestBuilder)
            .andDo(print());
}


这就是我的IDE中显示的内容。

java - Junit-andDo(print())未显示-LMLPHP

最佳答案

我认为您要查找的print()MockMvcResultHandlers

这是您的操作方法-

ResultActions resultActions = mockMvc.perform(requestBuilder)
                                     .andDo(MockMvcResultHandlers.print());

10-05 19:11