develog

[junit5] controller test @SpringBootTest 본문

Dev/junit

[junit5] controller test @SpringBootTest

냐옴 2020. 2. 29. 19:04

 

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
public class MyControllerTest {

    @Autowired
    MyController myController;

    @Autowired
    MockMvc mockMvc;

    @Autowired
    ObjectMapper objectMapper;

    @Test
    void test_00() throws Exception {
        assertThat(myController).isNotNull();
        assertThat(mockMvc).isNotNull();
        assertThat(objectMapper).isNotNull();
    }
}

'Dev > junit' 카테고리의 다른 글

[junit5] mockito  (0) 2020.03.07
[junit5] controller test @WebMvcTest  (0) 2020.03.02
[Junit] Test Assertion  (0) 2019.12.23
[junit4] pom.xml  (0) 2019.08.27
[junit] spring junit 설정2  (0) 2019.08.02
Comments