강의

멘토링

커뮤니티

Inflearn Community Q&A

iii66029804's profile image
iii66029804

asked

Toby's Clean Spring - Domain Model Pattern and Hexagonal Architecture Part 1

MockMvcTester 에도 MockMvc의 doPrint()같은 메소드가 있나요

Written on

·

113

0

찾아보다가 잘 못찾겠어서 문의 드립니다 ㅜㅜ

javaspringspring-bootjpa리팩터링ddd

Answer 2

2

tobyilee님의 프로필 이미지
tobyilee
Instructor

MockMvcTester는 테스트가 실패하면 doPrint() 처럼 API 호출 내역을 보여줍니다. 그런데 성공했을 때는 기본적으로 보여주지 않죠.

이번 강의에선 간단한 테스트만 만들어서 넣지 않았는데 만약 doPrint() 기능을 사용하고 싶으면 다음과 같이 apply() 를 이용하면 됩니다.

MvcTestResult result = mvcTester.post().uri("/api/members").contentType(MediaType.APPLICATION_JSON)
        .content(requestJson).exchange();

assertThat(result)
        .hasStatusOk()
        .apply(print())
        .bodyJson()
        .hasPathSatisfying("$.memberId", notNull())
        .hasPathSatisfying("$.email", equalsTo(request));

print()MockMvcResultHandlers 의 static method 입니다.

 

0

iii66029804님의 프로필 이미지
iii66029804
Questioner

좋은 답변 감사합니다~

iii66029804's profile image
iii66029804

asked

Ask a question