Inflearn brand logo image

인프런 커뮤니티 질문&답변

OMG님의 프로필 이미지
OMG

작성한 질문수

스프링 부트 개념과 활용

테스트 유틸

Junit5 outputcapture 해결 방법

해결된 질문

작성

·

659

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

백기선님의 프로필 이미지
백기선
지식공유자

좋은 내용 공유해 주셔서 감사합니다.

OMG님의 프로필 이미지
OMG

작성한 질문수

질문하기