Android Gradle任务:版本构建的connectedInstrumentTest?

gem*_*ini 10 android automated-tests gradle

有没有办法针对Release构建类型或任何其他自定义构建变体运行测试?

connectedInstrumentTest任务的默认行为是仅针对Debug构建变​​体运行测试

有任何想法吗?

rci*_*ati 14

AFAIK connectedInstrumentTest针对使用该testBuildType属性指定的构建类型运行.您可以尝试从命令行参数中进行动态读取:

android {
    testBuildType obtainTestBuildType()
}

def obtainTestBuildType() {
    def result = "debug";

    if (project.hasProperty("testBuildType")) {
        result = project.getProperties().get("testBuildType")
    }

    result
}
Run Code Online (Sandbox Code Playgroud)

然后用它来调用它

./gradlew connectedInstrumentTest -PtestBuildType=release