백앤드 이야기/JAVA&Spring
Junit5 메모
한희성
2020. 7. 4. 23:17
반응형
@WebMvcTest : 선언할 경우 @Controller, @ControllerAdvice 등 사용가능
단 Controller 에서만 사용가능
단 이 어노테이션 사용 경우 JPA 동작 안함
@Autowired
private MockMvc mvc; : 웹 API를 테스트 할 때 사용, 스프링 MVC 테스트의 시작점
이 클래스를 통해 http 메소드 API 테스트 가능
mvc.perform(get("hello")) : MockMvc를 통해 /hello 주소로 요청, 체이닝 지원
.andExpect(statuc().isOk()) : mvc.perform 의 결과를 검증
HTTP header의 Status 의 200을 검증한다
.andExpect(content().string(hello)) : mvc.perform의 결과를 검증, 검증 컨트롤러 해서의 리턴 값이 맞는지 검증
Junit 5에서 변경 된 것들
@BeforeClass -> @BeforeAll
@Before -> @BeforeEach
@After -> @AfterEach
@AfterClass -> @AfterAll
반응형