Android Instrumentation 测试不测试发布版本

标签 android android-testing

我目前正在使用 Android 仪器测试测试我的示例应用程序。默认情况下,项目创建 AndroidTest文件夹给我。我只是在文件夹中添加了更多测试用例。

我以前用expresso触发 UI 按钮,但现在我只想测试使用 androidTest,但是,androidTest 似乎没有测试我的发布版本。我有两个变体 productionReleasestageDebug在这种情况下。

每次我开始这个项目时

./gradlew mysample:connectedCheck 

或者
./gradlew mysample:connectedAndroidTest

它只测试
Task :mysample:connectedStageDebugAndroidTest

如果我想手动启动一个任务
./gradlew mysample:connectedProductionReleaeAndroidCheck 

它提示未在 mysample 中找到的任务
* What went wrong:
Task 'connectedProductionReleaseAndroidTest' not found in project ':mysample'.

connectCheck 不应该测试我项目中的所有变体吗? ( StageDebugProductionRelease )

来自 task --all
mysample:connectedCheck - Runs all device checks on currently connected devices.
mysample:connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.

最佳答案

刚刚试过...可以简单地运行./gradlew mysample:testDebugUnitTest./gradlew mysample:testReleaseUnitTest - 它运行调试或发布版本的测试。可以添加注释@RequiresDevice进行测试,以防万一。一个需要硬件传感器。productionReleasestageDebug看起来过于复杂(而且它也不匹配其余的命名 - 除非还有 productionDebugstageRelease),导致任务名称更长,建议缩短...

buildTypes {
    debug {}
    release {}
}
当我运行 ./gradlew mysample:connectedAndroidTest 时,这里我宁愿得到一个

Execution failed for task ':mysample:connectedDebugAndroidTest'. com.android.builder.testing.api.DeviceException: No connected devices!


关闭 Android Studio(以及它启动的 ADB 守护程序)后,我可以在硬件设备上运行测试。只有一个installDebugAndroidTest任务,但没有 installReleaseAndroidTest任务。 testBuildType 'release'可能会针对发布版本运行测试 - 问题只是 androidTestImplementation很可能没有包含(非常没用)。

关于Android Instrumentation 测试不测试发布版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48311749/

相关文章:

android - YouTube播放器旋转时停止

java - Android Studio 中 Android 库和 Java 库的区别

android - 开始使用 Robotium。未找到编辑文本

android - Appium测试中输入 "Enter key"

android - Espresso 如何点击放置在 listview 的第一项的 ImageView?

android - 找不到 AndroidJUnit4 的委托(delegate)运行程序 androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner

android - react native :-How to use a common drawer and toolbar across all pages with control

java - Android从服务器下载视频

android - 更改 Spinner 的分隔线颜色

android - 如何使用 Android Studio 检查 Android 应用程序的性能?