Skip to content

test: ViewModel unit test 인프라 추가 및 첫 테스트 작성#391

Merged
unam98 merged 1 commit into
developfrom
test/add-viewmodel-unit-test-infra
Jun 26, 2026
Merged

test: ViewModel unit test 인프라 추가 및 첫 테스트 작성#391
unam98 merged 1 commit into
developfrom
test/add-viewmodel-unit-test-infra

Conversation

@unam98

@unam98 unam98 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

작업 배경

  • AI 기반 개발/유지보수 시 회귀 버그를 수동 검증으로 잡기 어려워, ViewModel unit test 인프라를 도입해 안전망을 구축

변경 사항

영역 내용
gradle/libs.versions.toml, app/build.gradle MockK, Turbine, kotlinx-coroutines-test 의존성 추가 (testImplementation)
MyPageViewModelTest.kt LoadUserInfo 성공/실패, UpdateNickname 인텐트에 대한 상태 전이 테스트 3건
VisitorModeManagerTest.kt access token 값에 따른 방문자 모드 판별 로직 테스트 4건 (mockkObjectPreferenceManager 모킹, Robolectric 없이 plain JVM 테스트)

영향 범위

  • 테스트 코드 및 테스트 의존성만 추가, 프로덕션 코드/런타임 동작 변경 없음
  • 빌드 산출물(APK) 영향 없음 (testImplementation 스코프)

Test Plan

  • ./gradlew :app:testDebugUnitTest 전체 통과 확인
  • ./gradlew :app:assembleDebug 정상 빌드 확인
  • 후속 화면(Compose UI Test, Paparazzi) 테스트 레이어 확장

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added unit coverage for visitor mode behavior across different access token states.
    • Added view model tests for loading user info, error handling, and nickname updates.
  • Chores

    • Expanded test tooling support to include mocking, coroutine testing, and flow testing libraries.

MockK/Turbine/coroutines-test 의존성을 추가하고 MyPageViewModel,
VisitorModeManager에 대한 unit test를 작성해 AI 기반 개발 시
회귀를 자동으로 잡아낼 수 있는 안전망을 구축한다.
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Three new test dependencies (mockk, turbine, kotlinx-coroutines-test) are added to the version catalog and app/build.gradle. Two new unit test files are introduced: VisitorModeManagerTest verifies isVisitorMode across four access token values, and MyPageViewModelTest covers success/failure LoadUserInfo state transitions and the UpdateNickname intent using StandardTestDispatcher and Turbine.

Changes

Unit test additions

Layer / File(s) Summary
Test dependency setup
gradle/libs.versions.toml, app/build.gradle
Adds mockk and turbine version entries to the catalog, declares library entries for mockk, turbine, and kotlinx-coroutines-test, and wires all three as testImplementation in app/build.gradle.
VisitorModeManager access token tests
app/src/test/.../event/VisitorModeManagerTest.kt
Mocks PreferenceManager with mockk; four tests assert isVisitorMode returns true only for the "visitor" token and false for JWT, "none", and empty string values.
MyPageViewModel state and effect tests
app/src/test/.../mypage/MyPageViewModelTest.kt
Uses StandardTestDispatcher and Turbine to test three scenarios: success path populates user fields with error=null, failure path emits "네트워크 오류 (unknown)" error and ShowError effect, and UpdateNickname updates the nickname field in state.

Sequence Diagram(s)

sequenceDiagram
  participant Test as MyPageViewModelTest
  participant VM as MyPageViewModel
  participant Repo as UserRepository (mock)

  Test->>VM: dispatch LoadUserInfo
  VM->>Repo: getUserInfo()
  Repo-->>VM: emit Result.success(userInfo)
  VM-->>Test: state(isLoading=false, user fields set, error=null)

  Test->>VM: dispatch LoadUserInfo (failure)
  VM->>Repo: getUserInfo()
  Repo-->>VM: throw RuntimeException
  VM-->>Test: state(isLoading=false, error="네트워크 오류 (unknown)")
  VM-->>Test: effect ShowError emitted
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop hop, the tests now grow,
Mockk the token, watch it flow!
Visitor mode? True or false?
ViewModel state? No more flaws!
Turbine bubbles, coroutines play,
Bunny approves — ship it today! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding unit test infrastructure and initial tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/add-viewmodel-unit-test-infra

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/src/test/java/com/runnect/runnect/presentation/mypage/MyPageViewModelTest.kt (1)

102-104: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert ShowError message payload as well.

This currently validates only the effect type; an incorrect message would still pass. Assert the emitted ShowError message matches the expected error string.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/test/java/com/runnect/runnect/presentation/mypage/MyPageViewModelTest.kt`
around lines 102 - 104, The MyPageViewModelTest assertion only checks that the
emitted effect is MyPageEffect.ShowError, so an incorrect message payload could
still pass. Update the test around the effectTurbine.awaitItem() check to also
verify the ShowError message matches the expected error string, using the
MyPageEffect.ShowError symbol to locate the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@app/src/test/java/com/runnect/runnect/presentation/mypage/MyPageViewModelTest.kt`:
- Around line 102-104: The MyPageViewModelTest assertion only checks that the
emitted effect is MyPageEffect.ShowError, so an incorrect message payload could
still pass. Update the test around the effectTurbine.awaitItem() check to also
verify the ShowError message matches the expected error string, using the
MyPageEffect.ShowError symbol to locate the assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1599d79c-2026-4a62-a622-466b45e80c2f

📥 Commits

Reviewing files that changed from the base of the PR and between 7c6ec2e and 79a3e37.

📒 Files selected for processing (4)
  • app/build.gradle
  • app/src/test/java/com/runnect/runnect/presentation/event/VisitorModeManagerTest.kt
  • app/src/test/java/com/runnect/runnect/presentation/mypage/MyPageViewModelTest.kt
  • gradle/libs.versions.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant