Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Mac
- copy-dependencies
- Eclipse
- Quartz
- grep
- netsh
- maVen
- VirtualBox
- 단축키
- 네트워크
- port
- Windows
- IntelliJ
- 공통표준용어
- tomcat
- DB 도메인
- Windows 10
- import
- lsof
- ssh
- GIT
- find
- bash
- profile
- context
- Source
- resource
- web.xml
- xargs
- JavaScript
Archives
- Today
- Total
develog
[junit5] controller test @WebMvcTest 본문
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@ExtendWith(SpringExtension.class)
@WebMvcTest(controllers = {MyController.class})
public class MyControllerTest {
@Autowired
MockMvc mockMvc;
@Autowired
ObjectMapper objectMapper;
@Test
void test_00() throws Exception {
assertThat(mockMvc).isNotNull();
assertThat(objectMapper).isNotNull();
MvcResult mvcResult = mockMvc.perform(get("/myhello/test"))
.andDo(print())
.andReturn();
System.out.println("mvcResult = " + mvcResult);
String content = mvcResult.getResponse().getContentAsString();
System.out.println("content = " + content);
}
}
'Dev > junit' 카테고리의 다른 글
[junit] gradle junit5 (0) | 2020.04.21 |
---|---|
[junit5] mockito (0) | 2020.03.07 |
[junit5] controller test @SpringBootTest (0) | 2020.02.29 |
[Junit] Test Assertion (0) | 2019.12.23 |
[junit4] pom.xml (0) | 2019.08.27 |
Comments