Refactor: Ranking 도메인 관련 테스트 코드 리팩터링 및 테스트 커버리지 성능 개선 #45
Conversation
- 파일명 변경으로 인한 static 상수 import문 오류를 수정했습니다.
- Ranking 도메인 관련 테스트 코드를 리팩터링했습니다. - Service 레이어에서 Repository 기능을 불필요한 테스트를 Service 통합테스트로 수정했습니다. - Jacoco 테스트 커버리지 성능을 2% 개선했습니다. (72% -> 74%) issue #36
There was a problem hiding this comment.
Pull Request Overview
This PR refactors test code in the Ranking domain and boosts Jacoco coverage by 2%, including cleaning up imports and restructuring service-layer tests.
- Removed unused imports and variables across tests
- Refactored service vs. repository layer tests for Typing and Ranking domains
- Augmented and renamed tests to cover missing scenarios (e.g., non-existent member, anonymous user)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/test/java/dasi/typing/domain/phrase/PhraseRepositoryTest.java | Adjusted random-phrase loop bound from 25 to 30 |
| src/test/java/dasi/typing/api/service/typing/TypingServiceTest.java | Renamed tests, added missing-member scenario, updated exception assertions |
| src/test/java/dasi/typing/api/service/ranking/RankingServiceTest.java | Removed DateTimeUtil imports, simplified monthly ranking test |
| src/main/java/dasi/typing/api/service/phrase/PhraseService.java | Updated static import from CommonConstant to ConstantUtil |
Comments suppressed due to low confidence (1)
src/test/java/dasi/typing/api/service/typing/TypingServiceTest.java:66
- [nitpick] Test method names are a mix of
createTypingandcreateTypingTest. Choose a single consistent naming convention (with or withoutTestsuffix) to improve readability.
void createTypingTest() {
| // given | ||
| List<Phrase> phrases = new ArrayList<>(); | ||
| for (int i = 1; i <= 25; i++) { | ||
| for (int i = 1; i <= 30; i++) { |
There was a problem hiding this comment.
Using the hard-coded upper bound of 30 here can obscure intent—consider driving this from the phraseCount parameter to keep the test logic aligned with the scenario inputs.
| for (int i = 1; i <= 30; i++) { | |
| for (int i = 1; i <= Math.max(phraseCount, 30); i++) { |
| Code expectedErrorCode = assertThrows(CustomException.class, () -> { | ||
| typingService.saveTyping(authentication, serviceRequest); | ||
| }).getErrorCode(); | ||
|
|
||
| // then | ||
| assertThat(expectedErrorCode).isEqualTo(Code.NOT_EXIST_MEMBER); |
There was a problem hiding this comment.
[nitpick] You're mixing assertThatThrownBy and JUnit's assertThrows in different tests—standardize on one style for consistent exception assertions.
| Code expectedErrorCode = assertThrows(CustomException.class, () -> { | |
| typingService.saveTyping(authentication, serviceRequest); | |
| }).getErrorCode(); | |
| // then | |
| assertThat(expectedErrorCode).isEqualTo(Code.NOT_EXIST_MEMBER); | |
| // when & then | |
| assertThatThrownBy(() -> typingService.saveTyping(authentication, serviceRequest)) | |
| .isInstanceOf(CustomException.class) | |
| .extracting("errorCode") | |
| .isEqualTo(Code.NOT_EXIST_MEMBER); |
| void getMonthlyRanking() { | ||
| void getMonthlyRankingTest() { | ||
| // given | ||
| Phrase phrase = createPhrase(); |
There was a problem hiding this comment.
The phrase is never saved before typingRepository.saveAll(typings), which can cause a foreign-key constraint failure. Add phraseRepository.save(phrase) before saving typings.
#️⃣ 연관된 이슈
#36 #41
📝 작업 내용
📍 개선 사항
수정 전
수정 후
💬 리뷰 요구사항