My project has 2 different groups of tests. One group runs only with the default AndroidJUnitRunner
the other has to be run with a custom implementation TestRunner extends MonitoringInstrumentation
.
Currently I switch the testInstrumentationRunner
by editing the build.gradle
each time I need to run the other group of tests:
android{
defaultConfig {
//testInstrumentationRunner "my.custom.TestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
I know that flavours can have their own testInstrumentationRunner
but my current app already has 2 flavourDimensions
. Using flavours is actually intended to have different versions of an app. I need 2 versions of the test application, both testing the same app with different testInstrumentationRunner
s.
I tried to change the testInstrumentationRunner
by iterating over all test variants. There are actually multiple testInstrumentationRunner
properties:
android.testVariants.all { TestVariant variant ->
//readonly
variant.variantData.variantConfiguration.instrumentationRunner
variant.variantData.variantConfiguration.defaultConfig.testInstrumentationRunner
}
But as soon as android.testVariants
is called the build gets configured and all changes are not reflected in the build.
How can I change the testInstrumentationRunner (from a gradle plugin) dynamically?
I'd prefer to have 2 different gradle tasks, each using a different testInstrumentationRunner
but testing the same variant. Because I intent to create a gradle plugin the solution should work as plugin too.