I want to use a custom testInstrumentationRunner
for overriding the newInstance
method in order to use a custom application:
class UiTestJUnitRunner : AllureAndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
return super.newApplication(cl, TestApplication::class.java.name, context)
}
}
where that application is actually required to make the test execution work (since it skips some GDPR dialogs etc. at the startup):
class TestApplication : CoreApplication() {
override fun initDebugInfo(): DebugInfo {
return DebugInfo.builder()
.disableSomeDialogs...()
.build()
}
}
As you can see, I need to derive my TestJUnitRunner
from AllureAndroidJUnitRunner
. Unfortunately that AllureAndroidJUnitRunner
is not available at compile time since it is a transitive dependency of another library I'm using (Kaspresso).
During execution of the tests the class is available on the classpath and can be instantiated by the test framework. So, I can actually get an instance using reflection at runtime.
I've tried several approaches like including the transitive dependency explictly (which results in a duplication and instances are created which don't know of each other), reflection combined with byte code manipulation (but didn't get it running properly), as well as creating a custom runner redirecting all package-private, protected and public methods to an instance of the required testInstrumentationRunner
I've created by reflection (which also didn't succeed).
I'd be happy, if anyone has experience in this and can assist!