-
카테고리
-
세부 분야
백엔드
-
해결 여부
해결됨
Junit5 outputcapture 해결 방법
21.03.11 20:49 작성 조회수 412
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)
답변을 작성해보세요.
1
답변 1