非调试版本上的Android Gradle运行测试 [英] Android Gradle Running Tests on Non-Debug Builds

查看:162
本文介绍了非调试版本上的Android Gradle运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有三种不同构建类型的项目:调试,测试版和发布版。我的测试包总是为调试版本创建的,但QA使用测试版本,我们希望QA在他们的大量设备上运行这些测试。



我正在尝试创建一个测试版apk,它是由与测试版本相同的密钥签名的。通过Android-Gradle文档查看,我没有看到任何告诉我我无法做到这一点的事情,但我没有看到配置它。无论如何,我可以配置组装测试apk时使用哪个keystore?还是有没有办法创建一个未签名的测试apk?

解决方案

这是对你的问题不完整的答案,它记录了什么你不能这样做,但是在你的项目中运行 androidTest 测试的 connectedAndroidTest 任务是硬编码的以针对 debug 构建类型运行,而我没有看到将其指向不同构建类型的方法。



接受的建议如果运行:

 ,那么有办法在Gradle中列出任务依赖关系?并检查任务依赖关系树。 / gradlew tasks --all 

你在输出中得到这个:

 验证任务
------------------
app:check - 运行所有检查。 [app:lint]
app:connectedAndroidTest - 在连接的设备上安装并运行构建调试的测试。 [app:assembleDebug,app:assembleDebugTest]
app:connectedCheck - 在当前连接的设备上运行所有设备检查。 [app:connectedAndroidTest]
app:deviceCheck - 使用设备提供者和测试服务器运行所有设备检查。

connectedAndroidTest 任务的文档声明它对 debug 运行测试,并且任务依赖关系(您可以看到 -all 标志)确认任务取决于on assembleDebug



添加额外的构建类型和风格似乎不会影响对内置的依赖 debug 类型。



有可能在Gradle-fu比我的更大的情况下,测试依赖于不同的构建类型,但这样做很可能是脆弱的,因为它必然依赖Android Gradle插件中不支持的API。



尽管最直接地回答你的问题,但是,如果你只想对具有不同证书的版本运行测试,你可以改变 debug 版本上的签名配置以使用测试版证书:

  android {
s igningConfigs {
beta {
keyAlias'key'
keyPassword'password'
storeFile文件('/ path / to / beta_keystore.jks')
storePassword'password'
}
}
buildTypes {
debug {
signingConfig signingConfigs.beta
}
beta {
signingConfig signingConfigs.beta
}
}
}

我测试过了,以这种方式针对使用自定义密钥库的调试版本运行androidTest目标。然而,我怀疑这解决了你的问题,因为我怀疑你想要针对beta版构建运行测试,而不是使用beta 证书构建调试版。


I have a project with three different build types: debug, beta, and release. My test package is always created for debug builds, but QA uses the beta build and we want QA to run these tests on their vast array of devices.

I'm trying to create a testing apk for QA that is signed by the same key as the beta build. Looking through the Android-Gradle documentation, I don't see anything telling me that I can't do this, but I don't see anyway to configure this. Is there anyway I can configure which keystore is used when assembling a test apk? Or is there a way to create an unsigned test apk?

解决方案

This is an incomplete answer to your question in that it documents what you can't do, but the connectedAndroidTest task, which is what runs the androidTest tests in your project, is hardcoded to run against the debug build type, and I don't see a way to point it at a different build type.

Taking the advice from Is there a way to list task dependencies in Gradle? and examining the task dependency tree, if you run:

./gradlew tasks --all

you get this in your output:

Verification tasks
------------------
app:check - Runs all checks. [app:lint]
app:connectedAndroidTest - Installs and runs the tests for Build 'debug' on connected devices. [app:assembleDebug, app:assembleDebugTest]
app:connectedCheck - Runs all device checks on currently connected devices. [app:connectedAndroidTest]
app:deviceCheck - Runs all device checks using Device Providers and Test Servers.

The documentation for the connectedAndroidTest task claims it runs tests against debug, and the task dependencies (which you see with the -all flag) confirm that the task depends on assembleDebug.

Adding additional build types and flavors doesn't seem to affect the dependency on the built-in debug type.

It's possible that with greater Gradle-fu than mine, you could rewire the tasks to make the tests depend on a different build type, but doing this is likely to be fragile since it's bound to depend on things that aren't supported API in the Android Gradle plugin.

To answer your question most directly, though, if all you want is to run tests against a build with a different certificate, you could change the signing config on your debug build to use the beta certificate:

android {
    signingConfigs {
        beta {
            keyAlias 'key'
            keyPassword 'password'
            storeFile file('/path/to/beta_keystore.jks')
            storePassword 'password'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.beta
        }
        beta {
            signingConfig signingConfigs.beta
        }
    }
}

I tested it and I am able to run androidTest targets against debug builds that use a custom keystore in this way. However, I doubt this solves your problem, because I suspect you want to run your tests against the beta build, not a debug build with the beta certificate.

这篇关于非调试版本上的Android Gradle运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆