I can not inject MockMvc into integration test [Spring Boot]

0
@RunWith(SpringRunner.class)
@SpringBootTest
public class CustomerRestTest {

    private static final String BASE_URL = "http://localhost:8080";

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void indexTest() {
        MvcResult response = null;
        try {
            response = this.mockMvc.perform(MockMvcRequestBuilders.get(BASE_URL + "/customers").accept(org.springframework.http.MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
        } catch (Exception e) {
            System.out.println(e);
        }
        int codeStatus = response.getResponse().getStatus();
        assertEquals("index test expect status 200", 200, codeStatus);
    }

}
    
asked by anonymous 19.10.2016 / 16:47

1 answer

0

I think the only annotation @WebMvcTest was missing. See this excerpt from documentation .

    
20.10.2016 / 20:53