강의

멘토링

커뮤니티

Inflearn Community Q&A

omg's profile image
omg

asked

Spring Boot Concepts and Utilization

Test Utility

Junit5 outputcapture 해결 방법

Resolved

Written on

·

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)

javaspringspring-boot

Answer 1

1

whiteship님의 프로필 이미지
whiteship
Instructor

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

omg's profile image
omg

asked

Ask a question