SpringBootTest : No qualifying bean of type ‘org.springframework.test.web.servlet.MockMvc’ available:

Hope you have spring-boot-starter-web dependency. Not sure which version of Spring boot you use, but build mockMvc this way instead? @RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTest { @Autowired private WebApplicationContext webApplicationContext; private MockMvc mockMvc; @Before public void setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); }

mockMvc – Test Error Message

You can use the method status.reason(). For example: @Test public void loginWithBadCredentials() { this.mockMvc.perform( post(“/rest/login”) .contentType(MediaType.APPLICATION_JSON) .content(“{\”username\”: \”baduser\”, \”password\”: \”invalidPassword\”}”) ) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isUnauthorized()) .andExpect(status().reason(containsString(“Bad credentials”))) .andExpect(unauthenticated()); } MockHttpServletResponse: Status = 401 Error message = Authentication Failed: Bad credentials Content type = null Body = Forwarded URL = null Redirected URL = null Cookies = []