I cannot inject Mockmvc into integration test [Spring Boot]

Asked

Viewed 216 times

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);
    }

}

1 answer

0

I guess I just missed the Annotation @WebMvcTest. See this excerpt from documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.