Android Studio Instrumentation testing build variant

You can do testing on a different build variant; but only on one. The default is debug.

See this:
https://developer.android.com/studio/build/gradle-tips#change-the-test-build-type

Currently only one Build Type is tested. By default it is the debug
Build Type, but this can be reconfigured with:

android {
    ...
    testBuildType "staging"
}

AFAIK androidTest only works against the debug buildType.

You can use build flavours to do what you want, a good example can be found here: https://www.code-labs.io/codelabs/android-testing/#0

Alternatively, you can configure your testBuildType as following way so that you can decide to run any build type of the androidTest specifying the respective property from command line.

android {   
    ...

    if (project.hasProperty('androidTestRelease')) {
        testBuildType 'release'
    } else if (project.hasProperty('androidTestStaging')) {
        testBuildType 'staging'
    } else {
        testBuildType 'debug'
    }
    ...
}

From command line

./gradlew connectedCheck -PandroidTestStaging 

Leave a Comment