Skip to content

Test Code 작성 관련 이슈 정리 #172

Description

@easyhooon
  • CommonTest dependencies 내에 JUnit5 + mockk 관련 의존성 cannot resolve 관련 이슈

    • AndroidUnitTest 내에 테스트 라이브러리들을 주입하여, AndroidUnitest 패키지 내에서 테스트 코드 작성
  • Room Database 관련 Test Code 작성을 위한 Context 주입 관련 이슈

  • ViewModelTest init 블럭내에 Channel send Turbine 관련 이슈

    • app.cash.turbine.TurbineAssertionError: No value produced in 3s
    • awaitComplete() -> cancelAndIgnoreRemainingEvents() 로 변경하여 해결
      awaitComplete: 테스트 대상 Flow가 완전히 완료(complete)될 때까지 기다림.
      cancelAndIgnoreRemainingEvents(): 테스트를 강제로 종료하고(Flow의 수집을 취소) 남은 이벤트를 무시
    • 이벤트 중간 중간에 TestCoroutineScheduler.advanceUntilIde() 함수를 호출하여 이벤트 호출을 완료
  • ViewModelTest Navigation Argument + SavedStateHandle 관련 이슈(화면 이동시 전달받는 인자)

    • kotlinx.serialization.MissingFieldException: Fields [bandalartId, bandalartTitle, bandalartProfileEmoji, bandalartChartImageUri] are required for type with serial name 'com.nexters.bandalart.core.navigation.Route.Complete', but they were missing
    • CompleteViewModelTest savedStateHandle 모킹 관련 이슈
    • Verification failed: call 1 of 1: BandalartRepository(#4).upsertBandalartId(eq(1), eq(true), any())) was not called java.lang.AssertionError: Verification failed: call 1 of 1: BandalartRepository(#4).upsertBandalartId(eq(1), eq(true), any())) was not called
    • mockK suspend fun 모킹 관련 이슈(함수 마지막 인자로 continuation 인자가 추가됨)
      No answer found for: ...continuation {}) mockk/mockk#957
    • repository 모킹할때 relaxUnitFun 옵션 활성화 하여 해결
    mockBandalartRepository = mockk<BandalartRepository>(relaxUnitFun = true)
  • HomeViewModelTest 관련 이슈

     // Compose 리소스 모킹
     mockkStatic("org.jetbrains.compose.resources.StringResourcesKt")
     // getString 함수 suspend 함수 
     coEvery { org.jetbrains.compose.resources.getString(any()) } returns "Mocked String"
  • UI Test 관련 이슈
    reference)
    https://github.com/DroidKaigi/conference-app-2024

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationtest-codingtasks related to writing or updating test code, scripts, or test cases.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions