Testing multiple build variants simultaneously

Viewed 165

I created a Test case (using Espresso 2) for an application with multiple Flavors and I would like to run that Test for all the flavors simultaneously (or at least one after the other). Is that possible? At the moment I am only able to run the test for the current Build Variant selected, so I have to manually change the Build Variant and run the test again, one by one.

Thank you very much.

1 Answers

If you know the names of the gradle tasks that install your tests you can run this from the root of your project in the terminal:

./gradlew install{VariantName1, VariantName2, VariantName3}Test

This assumes you have a module build.gradle file with variants set up according to the guide. So something along these lines:

apply plugin: 'com.android.application'

android {

    ...

    flavorDimensions "myFlavorDimension"
    productFlavors {
        VariantName1 {
            ...
        }
        VariantName2 {
            ...
        }
        VariantName3 {
            ...
        }
    }
    
    ...

}

dependencies {
    ...
}

You can find these gradle task names either in Android Studio in the Gradle Tab (right side of GUI) under you moduleName->Tasks->install

Or you can find them in the terminal with:

./gradlew tasks | grep install

I'm sure there is some Regex that could grab only the ones of interest programmatically as well, but I'm not a regex buff. If you want to leave a comment with something that would work, I'd be happy to edit and add later.

Related