Conversation
- BehaviorSpec 예시에서 runTest 제거, coroutineTestScope 패턴으로 통일 - Given/When/Then 코드 배치 규칙을 테스트 작성 규칙 섹션으로 통합 - 도메인/ViewModel 계층별 중복 배치 규칙 제거, 특이사항만 잔류 - 코루틴 테스트 항목 신설 (coroutineTestScope, backgroundScope 규칙) - private 검증 금지 항목을 테스트 기준점에 추가 - Mockk 사용 기준에 인터페이스 추상화 대안 명시 - 예시 코드를 실전 클래스 대신 가상 예제(FooTest)로 교체
…allbackAwareMusicRepository)
- runTest {} 래핑 제거, coroutineTestScope = true 선언으로 통일
- scope 주입 클래스는 CoroutineScope(UnconfinedTestDispatcher(testScheduler)) 사용
- 코루틴 시간 조작은 testScheduler.advanceTimeBy() 사용
- TimerTestUtils에 TestScope 없이 사용 가능한 elapse() 오버로드 추가
- Given/When/Then 배치 규칙 준수 (Given: 준비, When: 객체+액션, Then: 검증)
- docs/testing.md 코루틴 테스트 섹션을 실제 Kotest 동작에 맞게 수정
- seed 기반 인덱스 하드코딩 → 5곡 모두 한 번씩 방문하는 행동 기반 검증으로 교체 - 셔플 ON 상태에서 OFF로 토글 시 currentIndex가 원래 인덱스를 유지하는 케이스 추가
…시 패턴으로 교체 - StateFlow conflation으로 Loading이 합쳐져 Success 상태 하나만 방출됨을 확인 - while 루프 + 재시도 카운터 → awaitItem() 단일 호출로 단순화 - 불필요해진 fail import 제거
- core/model/TrackFixtures.kt 신규 생성 (testTrack 함수) - PlayQueueManagerTest, PlaylistDetailViewModelTest, ZenMusicSelectViewModelTest, MiniPlayerViewModelTest, FallbackAwareMusicRepositoryTest 5개 파일 로컬 makeTrack 제거 후 testTrack으로 치환 - 호출 시 named argument 사용 강제
- FOCUS RUNNING 상태에서 PomodoroSkip 시 세션이 BREAK로 전환되고 RUNNING 유지 검증 - FakeZenPlayerBinder.skipPomodoro()에 실제 세션 전환 로직 추가
- focusDuration 설정 변경 시 현재 세션의 timerState(RUNNING)가 유지되는지 검증
- Dispatchers.setMain()을 각 Given에서 beforeTest로 통합 (4개 파일) - PlayQueueManager 셔플 OFF 토글 테스트에 고정 seed(42) 적용으로 결정론적 검증 보장 - PomodoroManagerTest elapse() 행동 코드를 Then → When 블록으로 이동 (4곳) - FallbackAwareMusicRepositoryTest Then 블록을 반환값/isFallback 검증으로 분리 - MiniPlayerViewModelTest fakeTrack을 사용하는 Given 블록 내부로 스코프 이동 - PlayQueueManagerTest makeManager() 생성을 Then → When 블록으로 이동
Coverage Report
|
There was a problem hiding this comment.
Pull request overview
테스트 코드 전반의 패턴을 coroutineTestScope 기반으로 통일하고, Turbine 소비 방식/공통 픽스처 분리를 통해 flaky 가능성을 낮추며 주요 컴포넌트의 누락 시나리오를 보강하는 PR입니다.
Changes:
- 테스트 전역에서
Dispatchers.setMain/resetMain,coroutineTestScope = true사용 패턴을 정리하고 Turbine 소비 로직을 명시화 testTrack()공통 픽스처 및 타이머 테스트 유틸(elapseoverload) 추가로 중복 제거- Pomodoro/Zen/PlayQueue/PlaylistDetail 등에서 신규 시나리오 테스트 케이스 추가 및 FakeBinder 동작 보강
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/testing.md | 코루틴 테스트/코드 배치 규칙 및 Fake/Mockk 가이드 정리 |
| app/src/test/java/com/happyseal/zenplayer/core/model/TrackFixtures.kt | 테스트용 testTrack() 공통 픽스처 추가 |
| app/src/test/java/com/happyseal/zenplayer/zen/musicselect/ZenMusicSelectViewModelTest.kt | testTrack() 적용 및 Retry 케이스의 Turbine 소비 방식 변경 |
| app/src/test/java/com/happyseal/zenplayer/zen/ZenViewModelTest.kt | Dispatchers.setMain 설정 방식 정리 + Pomodoro skip 시나리오 추가 |
| app/src/test/java/com/happyseal/zenplayer/zen/MiniPlayerViewModelTest.kt | testTrack() 적용 및 setMain 설정 위치 정리 |
| app/src/test/java/com/happyseal/zenplayer/zen/FakeZenPlayerBinder.kt | Pomodoro skip 동작을 상태 전환 가능하게 보강 |
| app/src/test/java/com/happyseal/zenplayer/features/timer/domain/TimerTestUtils.kt | TestCoroutineScheduler 기반 elapse() 유틸 추가 |
| app/src/test/java/com/happyseal/zenplayer/features/timer/domain/TimerEngineTest.kt | runTest 제거, coroutineTestScope 기반으로 타이머 테스트 구조 변경 |
| app/src/test/java/com/happyseal/zenplayer/features/timer/domain/PomodoroManagerTest.kt | runTest 제거, coroutineTestScope 기반으로 구조 변경 + 신규 케이스 추가 |
| app/src/test/java/com/happyseal/zenplayer/features/playlist/ui/PlaylistDetailViewModelTest.kt | testTrack() 적용 + 트랙 제거 후 목록 갱신 케이스 추가 |
| app/src/test/java/com/happyseal/zenplayer/features/player/data/PlayQueueManagerTest.kt | 셔플 테스트를 행동 기반 검증으로 변경 및 OFF 복귀 케이스 추가 |
| app/src/test/java/com/happyseal/zenplayer/features/music/data/FallbackAwareMusicRepositoryTest.kt | runTest 제거, coroutineTestScope 기반으로 구조 정리 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/src/test/java/com/happyseal/zenplayer/features/timer/domain/TimerEngineTest.kt
Outdated
Show resolved
Hide resolved
app/src/test/java/com/happyseal/zenplayer/features/timer/domain/PomodoroManagerTest.kt
Show resolved
Hide resolved
app/src/test/java/com/happyseal/zenplayer/zen/musicselect/ZenMusicSelectViewModelTest.kt
Outdated
Show resolved
Hide resolved
- PomodoroManagerTest: scope를 변수로 추출하고 Then 블록 마지막에 dispose()/cancel() 추가 - ZenMusicSelectViewModelTest: Retry 후 Loading 상태 방출 시 건너뛰도록 flaky 테스트 수정
- scope를 변수로 추출하고 Then 블록 마지막에 dispose()/cancel() 추가
- dispose()/scope.cancel() 호출 필요성 및 예시 코드 추가 - TestCoroutineScheduler 공유 시 주의사항 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
coroutineTestScope패턴과 TurbineawaitItem명시 패턴으로 통일하고, 공통 픽스처(TrackFixtures)를 분리하여 재사용성을 높임PomodoroManager,ZenViewModel,PlayQueueManager,PlaylistDetailViewModel등 주요 컴포넌트에 누락된 시나리오 케이스를 보완Key Changes
TrackFixtures.kt공통 픽스처 파일 신규 추출 — 여러 테스트에서makeTrack()재사용ZenMusicSelectViewModelTest: Retrywhile루프 → TurbineawaitItem명시 패턴으로 교체PomodoroManager,TimerEngine,FallbackAwareMusicRepository:coroutineTestScope패턴으로 통일PomodoroManagerTest: RUNNING 상태에서 설정 변경 시 상태 유지 케이스 추가ZenViewModelTest: skip 액션 시나리오 추가PlayQueueManagerTest: 셔플 테스트를 행동 기반 검증으로 교체, 셔플 OFF 복귀 케이스 추가PlaylistDetailViewModelTest: 트랙 제거 성공 후 목록 갱신 케이스 추가docs/testing.md: 내용 불일치 및 중복 정리Technical Details
coroutineTestScope패턴:TestScope+UnconfinedTestDispatcher를 공통 헬퍼로 감싸 보일러플레이트 제거awaitItem패턴:while루프 기반의 비결정적 대기를 제거하고 명시적 아이템 소비로 교체TimerTestUtils.kt헬퍼 신규 추가로 타이머 관련 테스트 공통 로직 집중FakeZenPlayerBinder소폭 조정으로 신규 시나리오 테스트 지원Rationale
while루프 기반 polling은 타이밍에 민감하고 flaky test를 유발할 수 있어 Turbine의 구조적 대기 방식으로 대체coroutineTestScope패턴 통일로TestCoroutineDispatcher누수 경고 제거