I am trying to use a custom AndroidJUnitRunner implementation with ActivityScenarios. The goal is to provide the unit tests an Application instance that is KodeinAware.
However, despite following the examples found online, the custom runner does not appear to be used. I am testing by printing a statement in the below override:
class KodeinAwareRunner : AndroidJUnitRunner() {
@Throws(Exception::class)
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
println("hellooOOOOooooo")
return super.newApplication(
cl, KodeinAwareApplication::class.java.name, context
)
}
}
I have also updated the build.gradle to utilize the custom runner:
testInstrumentationRunner "my.custom.testrunner.KodeinAwareRunner"
To be extra sure I was not missing the print statement in logs, I also have the following initialization code in my KodeinAware Activity:
override val kodein: Kodein by lazy {
(applicationContext as KodeinAware).kodein
}
As a result, I keep getting the following exception, suggesting that the custom test runner is not being utilized:
java.lang.ClassCastException: android.app.Application cannot be cast to org.kodein.di.KodeinAware
I would like to emphasize that the custom runner is only for regular Android unit tests and NOT the instrumentation tests.
I am also not using the production Application class due to the aforementioned tests being part of an Android library, so I do not want an Application in the module.
Does anyone know what I may be doing wrong or whether there are steps I missed?