1. pom.xml에 다음 라이브러리를 설정한다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2. 테스트할 클래스를 선택한 후 JunitTest4를 선택한다.
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
public class UserConrollerTest {
@Autowired
MockMvc mockMvc;
@Test
public void test() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/user/all"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultHandlers.print());
}
}
MOCK: 톰켓 x, RANDON_PORT : 톰켓 O, NONE: 서블릿 환경 X
'Programming Bookmark > Spring - Java' 카테고리의 다른 글
springboot actuator prometheus 사용시 io.prometheus.client.CollectorRegistry 사용하기(io.prometheus.client.Counter) (0) | 2021.01.15 |
---|---|
Missing required configuration "key.serializer" which has no default value - spring kafka 설정시 에러 (0) | 2020.04.09 |
spring dispatcher render 직전 디버그 (0) | 2020.03.03 |
java local ip spring에서 쉽게 얻기 (0) | 2019.12.03 |
Spring security 래퍼런스와 Github 주소 공유 (0) | 2019.05.09 |