I use flavors in my project and I wanna add add instrumentation tests specific for each flavor.
So I created
MyApplication/src/androidTestFlavor1/java/com.package.test
MyApplication/src/androidTestFlavor2/java/com.package.test
But it doesn't work correctly.
So, I've tried to configure it in build.gradle, I've added
android {
...
sourceSets {
flavor1{
instrumentTest.setRoot('src/instrumentationTestFlavor/java')
}
}
...
}
but I get error:
Error:(59, 0) Could not find property 'instrumentTest' on source set ding.
What's the best solution here?
When you setup a new project in android studio it creates a main folder and an androidTest folder. Gradle uses the androidTest folder for common tests across all flavors. See link. So if you try try to write a flavour specific test and put it in the androidTest folder, it will be run against all your flavors and will probably fail.
So if you want to create flavor specific tests you need to add a new test folder for that flavor containing the java folder and your test. The naming convention has to be androidTestFlavorName. See image below.

来源:https://stackoverflow.com/questions/26297042/flavors-and-instrumentation-tests-gradle-configuration