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