Issue
I'm new to JUnit testing. I'm now trying to test a Spring endpoint using MockMvc
, but the andDo(print())
method can not be found.
Are there any things I have to import in order to use this or what?
@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());
}
Here's what shown in my IDE:
Solution
I think the print()
you are looking for is in MockMvcResultHandlers
Here is how you can do it -
ResultActions resultActions = mockMvc.perform(requestBuilder)
.andDo(MockMvcResultHandlers.print());
Answered By - Rishikesh Dhokare