https://kotlinlang.org logo
#dagger
Title
# dagger
j

Joan Colmenero

04/30/2020, 11:12 AM
Hello! I'm facing this error whenever I want to create UI tests with Espresso using Dagger
java.lang.RuntimeException: android.app.Application does not implement dagger.android.HasAndroidInjector
Any idea, why? It only happens with UI tests, the app runs and everything is injected correctly.
j

Jovan

04/30/2020, 11:15 AM
Do you use some kind of Test Application class?
w

wasyl

04/30/2020, 11:19 AM
You probably need to create custom test runner (
AndroidJUnitRunner
) and override
fun newApplication
method to call something like
super.newApplication(cl, TestApplication::class.java.name, context)
And set
android.defaultConfig.testInstrumentationRunner = <your custom runner>
That’s just a quick fyi that it’s usually done, I don’t know if instrumentation tests should use your default class from manifest by default or not
j

Joan Colmenero

04/30/2020, 11:23 AM
@Jovan No I do not, shall I?
@wasyl Do you have a sample where I can guide to do it? I get you but not 100%
34 Views