Bound Multiple Times issue when using Hilt for UI Test, TestInstalln
See original GitHub issueHello, I’ve created a fake urlprovider binding and annotated with @TestInstallIn
@Module
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [UrlModuleBindings::class]
)
abstract class FakeUrlBindings {
@Binds
abstract fun bindsUrlProvider(urlProvider: FakeUrlProvider): UrlProvider
}
This is inside androidTest my Prod UrlProvider looks like
@Module
@InstallIn(SingletonComponent::class)
abstract class UrlModuleBindings {
@Binds
abstract fun bindsUrlProvider(urlProvider: DefaultUrlProvider): UrlProvider
}
This is Original Binding
when I’m running the UI test getting the error **UrlProvider is bound multiple times:**
As per the documentation everything seems correct, can I please know what is the issue with this.
Have followed https://dagger.dev/hilt/testing.html
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Bound Multiple Times issue when using Hilt for UI Test ...
when I'm running the UI test getting the error UrlProvider is bound multiple times: As per the documentation everything seems correct, can I ......
Read more >Hilt testing guide | Android Developers
Hilt isn't necessary for unit tests, since when testing a class that uses constructor injection, you don't need to use Hilt to instantiate...
Read more >egghead-next | The frontend for egghead.io | UI Testing library - kandi
Implement egghead-next with how-to, Q&A, fixes, code snippets. kandi ratings ... Bound Multiple Times issue when using Hilt for UI Test, TestInstalln.
Read more >Hilt Testing Best Practices in the MAD Skills series - Medium
This time we'll be focusing on how to write tests with Hilt and some of the best practices to be aware of. Since...
Read more >Newest 'android-instrumentation' Questions - Stack Overflow
Bound Multiple Times issue when using Hilt for UI Test, TestInstalln. I've created a fake urlprovider binding and annotated with TestInstallIN @Module ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ankitkhare,
Sorry for the delay!
To fix this, you need to remove the
@Module.includes
fromAppModule
.The issue is that while Hilt does uninstall the explicit
UrlModuleBindings
module usage in the generated code, it’s still transitively included byAppModule
.In Hilt, you shouldn’t ever need to use
@Module.includes
unless you’re including a non-Hilt module that you can’t use@InstallIn
on directly. In this case,UrlModuleBindings
already has@InstallIn
on it so it shouldn’t be included by another module.Thanks for the sample project @ankitkhare!
I was able to repro the issue in your project, however it may take me a few days before I can start debugging and fixing it. I’ll update here once I know something.