Search code examples
androidgradletestingandroid-jetpack-composedagger-hilt

Android Hilt. Unresolved reference: TestInstallIn


module file:

@Module
@TestInstallIn(components = [ActivityRetainedComponent::class],
    replaces = [ThoughtTrackerModule::class])
object FakeThoughtTrackerModule {
    @Provides
    fun provideIsDateDifferentFromCurrentUseCase(): IsDateEqualToCurrentUseCase =
        IsDateEqualToCurrentUseCase(LocalDateTime.now().plusDays(1))
    @Provides
    fun provideGetCurrentDateInTimestampUseCase(): GetCurrentDateInTimestampUseCase =
        GetCurrentDateInTimestampUseCase()
    @Provides
    fun provideThoughtTrackerService(): ThoughtTrackerService =
        ThoughtTrackerService(Firebase.firestore.collection("users"), Firebase.auth)
    @Provides
    fun provideThoughtTrackerItemService(): ThoughtTrackerItemService =
        ThoughtTrackerItemService(Firebase.firestore.collection("users"), Firebase.auth)
}

build.gradle.kts:

val hilt_version = "2.50"
implementation("com.google.dagger:hilt-android:$hilt_version")
ksp("com.google.dagger:hilt-android-compiler:$hilt_version")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0")
androidTestImplementation("com.google.dagger:hilt-android-testing:$hilt_version")
kspAndroidTest("com.google.dagger:hilt-android-compiler:$hilt_version")

I've tried using different versions of hilt, invalidating caches of Android Studio, running ./gradlew clean build, but to no result


Solution

  • You specify "com.google.dagger:hilt-android-testing:$hilt_version" for androidTestImplementation. So you need to put the FakeThoughtTrackerModule in the androidTest directory.