0

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!

ceedee
  • 371
  • 1
  • 11

1 Answers1

0

I solved this by NOT requiring to derive from AllureAndroidJUnitRunner. Instead I added a separate manifest in the debug folder overriding application:name to the TestApplication:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="de.xyz...">

    <application
        tools:replace="android:name"
        android:name=".TestApplication"/>
</manifest>

It is required to put it into the debug folder since manifest merging will not take anything from androidTest.

ceedee
  • 371
  • 1
  • 11