google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.41k stars 2.01k forks source link

The application is not called when I run Android UI Testing with HiltAndroidTest. #3180

Closed DreamSkyMXDan closed 2 years ago

DreamSkyMXDan commented 2 years ago

I tested compostTestRule in compose project with Application. The Application class can also be called when running a UI test without Hilt DI. But when I added Hilt DI, had to annotate the android UI test as HiltAndroidTest and add HiltAndroidRule, the application class would not be called.

There are some initialization work in application class, so my launcher activity depends on the result from the application class. How should we handle this when Hilt is used as DI? Is there a sample project I can refer to?

Thanks

Chang-Eric commented 2 years ago

This sounds like you want to use https://dagger.dev/hilt/testing#custom-test-application?