-
Notifications
You must be signed in to change notification settings - Fork 2
#23 Story 테스트 코드 작성 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
noxknow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전체적으로 테스트 코드가 잘 구조화되어 있고, 각 기능에 대한 검증을 명확히 하고 있어 인상적입니다! 특히, 유효한 요청과 유효하지 않은 요청에 대해 잘 구분하고 테스트하는 부분이 좋았습니다. 😁
| assertThat(actual).hasSize(1); | ||
| assertThat(actual.getFirst()) | ||
| .usingRecursiveComparison() | ||
| .isEqualTo(expected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
응답을 usingRecursiveComparison()으로 검증하는 방식은 처음 봤는데 테스트의 신뢰성과 가독성을 동시에 확보할 수 있어 좋았습니다. 👍
다만, JsonPath와 비교했을때 응답 구조 변경에 민감한 특성이 있어서, 향후 API 스펙이 변경될 경우 테스트 유지보수 측면에서 부담이 될 수 있다는 점도 함께 고려되면 좋을 것 같습니다!
| @ParameterizedTest | ||
| @DisplayName("❗ 원고 정보 수정 - 유효하지 않은 요청값") | ||
| @MethodSource("invalidStoryRequests") | ||
| void updateStory_invalidRequest(UpdateStoryRequest invalidRequest) throws Exception { | ||
| // when // then | ||
| mockMvc.perform(put(BASE_URL + "/{storyId}", storyId) | ||
| .header(AUTHORIZATION, testAuthUtils.getAccessToken(member)) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(objectMapper.writeValueAsString(invalidRequest)) | ||
| ) | ||
| .andExpect(status().isBadRequest()); | ||
| } | ||
|
|
||
| private static Stream<UpdateStoryRequest> invalidStoryRequests() { | ||
| return Stream.of( | ||
| new UpdateStoryRequest(null, ""), | ||
| new UpdateStoryRequest("", null), | ||
| new UpdateStoryRequest("a".repeat(51), null) | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MethodSource를 활용한 테스트로 유효성 검증 케이스들을 명확히 분리하고 반복을 줄인 점이 인상 깊네여! 😊
| @ParameterizedTest | ||
| @DisplayName("❗ Story 이름 변경 - 유효하지 않은 요청") | ||
| @MethodSource("invalidFileNameRequests") | ||
| void updateDndName_invalidRequest(CommonUpdateFileNameRequest invalidRequest) throws Exception { | ||
| // when // then | ||
| mockMvc.perform(patch(BASE_URL + "/{id}/title", story.getId()) | ||
| .header(AUTHORIZATION, testAuthUtils.getAccessToken(member)) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(objectMapper.writeValueAsString(invalidRequest))) | ||
| .andExpect(status().isBadRequest()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 유효성 검증 실패 시 상태 코드(400)만 검증하고 있는데, 클라이언트가 어떤 필드가 잘못되었는지를 알 수 있도록 응답 본문도 함께 검증하면 좋을 것 같아요..!
given-dragon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다~
📌 연관된 이슈
✌️ Changes
기타