@CustomTestApplication value cannot be annotated with @HiltAndroidApp

Viewed 1814

If the Application has a Custom Application object. It is needed to annotate this with @HiltAndroidApp ex: @HiltAndroidApp class AppCore: Application

Appcore has some initialization logic which is needed for the app to run

Now in the Instrumentation tests We also need to Extend the custom Application object. @CustomTestApplication(AppCore::class) interface HiltTestApplication

This gives an error @CustomTestApplication value cannot be annotated with @HiltAndroidApp

Is there any other way of using HILT in instrumentation tests with custom Application objects

public abstract interface HiltTestApplication {
                ^
  @CustomTestApplication value cannot be annotated with @HiltAndroidApp. Found: AppCore
1 Answers

As suggested in the issue tracker. Can you abstract your initialization logic into a base class, say BaseAppCore : Application then in your prod application extend it @HiltAndroidApp AppCore : BaseAppCore and then for tests make Hilt generate a test app based on your abstract one, @CustomTestApplication(BaseAppCore::class) interface AppCoreTestApplication. It might be best to file this issue in https://github.com/google/dagger/issues

Related