Android Studio Instrumentation 测试构建变体
Android Studio Instrumentation testing build variant
所以我正在尝试使用自定义构建变体 mock 编写仪器测试。在这个构建变体中,我模拟了我的 类 和服务器。当我自己尝试使用模拟构建时,它工作正常,但我似乎无法使用我的模拟构建进行测试。这是我在 Android Studio 中的配置。
我在 运行 进行测试时遇到了一些问题,所以我尝试卸载我的应用程序的所有版本,但我的模拟版本除外,但我不断收到此错误:
Test running startedTest running failed: Unable to find instrumentation target package: com.teamtreehouse.review.debug
然而,当我尝试 运行 针对调试构建变体进行测试时,它工作正常。它安装我的调试版本,然后进行 运行 测试。
AFAIK androidTest 仅适用于调试 buildType。
你可以使用构建风格来做你想做的事,一个很好的例子可以在这里找到:https://www.code-labs.io/codelabs/android-testing/#0
您可以在不同的构建变体上进行测试;但只有一个。默认是调试。
看这个:
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"
}
或者,您可以按以下方式配置 testBuildType,以便您可以决定 运行 指定相应 属性 的任何 androidTest 构建类型从命令行。
android {
...
if (project.hasProperty('androidTestRelease')) {
testBuildType 'release'
} else if (project.hasProperty('androidTestStaging')) {
testBuildType 'staging'
} else {
testBuildType 'debug'
}
...
}
从命令行
./gradlew connectedCheck -PandroidTestStaging
所以我正在尝试使用自定义构建变体 mock 编写仪器测试。在这个构建变体中,我模拟了我的 类 和服务器。当我自己尝试使用模拟构建时,它工作正常,但我似乎无法使用我的模拟构建进行测试。这是我在 Android Studio 中的配置。
我在 运行 进行测试时遇到了一些问题,所以我尝试卸载我的应用程序的所有版本,但我的模拟版本除外,但我不断收到此错误:
Test running startedTest running failed: Unable to find instrumentation target package: com.teamtreehouse.review.debug
然而,当我尝试 运行 针对调试构建变体进行测试时,它工作正常。它安装我的调试版本,然后进行 运行 测试。
AFAIK androidTest 仅适用于调试 buildType。
你可以使用构建风格来做你想做的事,一个很好的例子可以在这里找到:https://www.code-labs.io/codelabs/android-testing/#0
您可以在不同的构建变体上进行测试;但只有一个。默认是调试。
看这个: 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"
}
或者,您可以按以下方式配置 testBuildType,以便您可以决定 运行 指定相应 属性 的任何 androidTest 构建类型从命令行。
android {
...
if (project.hasProperty('androidTestRelease')) {
testBuildType 'release'
} else if (project.hasProperty('androidTestStaging')) {
testBuildType 'staging'
} else {
testBuildType 'debug'
}
...
}
从命令行
./gradlew connectedCheck -PandroidTestStaging