인프런 커뮤니티 질문&답변
Junit5 outputcapture 해결 방법
해결된 질문
작성
·
672
2
@WebMvcTest
@ExtendWith(OutputCaptureExtension.class) // 추가
class SampleControllerTest {
@MockBean
SampleService sampleService;
@Autowired
MockMvc mockMvc;
@Test // 메서드 파라미터 추가
void hello(CapturedOutput capturedOutput) throws Exception {
when(sampleService.getName()).thenReturn("whiteship");
mockMvc.perform(get("/hello")).andExpect(content().string("hello whiteship"));
assertThat(capturedOutput.toString()).contains("holoman")
.contains("skip");
}
}
강의 촬영 당시랑 버전업 되면서 바뀐 부분이 있습니다 최근 스프링부트 쓰셔서 안되시는분들 참고하세요!
(스프링 부트 2.39)





