Flavors and instrumentation tests - gradle configuration
Asked Answered
F

1

2

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?

Flurried answered 10/10, 2014 at 10:13 Comment(1)
Did the answer work for you? If not, can you post what solution you have. Im having the same problem :-)Sundsvall
S
5

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

Steatopygia answered 4/3, 2015 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.