Flavors and instrumentation tests - gradle configuration

0
0

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?

  • You must to post comments
0
0

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.

enter image description here

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website