Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bound Multiple Times issue when using Hilt for UI Test, TestInstalln

I've created a fake urlprovider binding and annotated with TestInstallIN

@Module
@TestInstallIn(
    components = [SingletonComponent::class],
    replaces = [UrlModuleBindings::class]
)
abstract class FakeAppBindings {

    @Binds
    abstract fun bindsUrlProvider(urlProvider: FakeUrlProvider): UrlProvider
}

my Prod UrlProvider looks like

@Module
@InstallIn(SingletonComponent::class)
abstract class UrlModuleBindings {

    @Binds
    abstract fun bindsUrlProvider(urlProvider: DefaultUrlProvider): UrlProvider
}

when I'm running the UI test getting the error UrlProvider is bound multiple times:

As per the documentation everything seems correct, can I know what is the issue with this.

like image 896
Ankit Khare Avatar asked Oct 14 '25 04:10

Ankit Khare


1 Answers

Thanks to Brad, the issue was with the AppModule, I was using Includes whereas hilt doesn't need Includes as it already has InstallIn annotation for this purpose. Once I remove it the UI test starts to work.

More details.

https://github.com/google/dagger/issues/3209

like image 102
Ankit Khare Avatar answered Oct 18 '25 03:10

Ankit Khare