android - 如何将 Espresso UI 测试编译成一个版本?

标签 android android-gradle-plugin android-espresso android-testing

我目前正在尝试将 Espresso 测试添加到 release APK 中。在我们的案例中,我们必须测试正在发布的实际内容,因此 UI 测试必须包含在发布中。

所以我的主要问题是:如何最好地完成这项工作?到目前为止,互联网上的研究没有给我任何结果。

我已经尝试将构建脚本中的 androidDebugTest 更改为 compile:

compile 'com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
}

还有这里:

compile 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'design'
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}

但是调用之后

./gradlew assembleRelease --info --debug

我收到此错误消息:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/annotation/Generated.class
...
BUILD FAILED

此外,通常有两个 gradle 任务 assembleDebugassembleDebugAndroidTest 与 Espresso 一起工作。但是,由于没有 assembleReleaseAndroidTest 任务,发布版本在做什么?

提前感谢您的建议!

最佳答案

您无法将测试编译到应用 APK 中,但您可以针对发布构建类型进行测试。在您的情况下,您的发布 Artifact 将包含两个 APK,即常规应用 APK 和测试 APK。参见 https://stackoverflow.com/a/18064368/1231827 .

关于android - 如何将 Espresso UI 测试编译成一个版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221034/

相关文章:

android - Espresso - 对全屏 Activity 执行操作失败 - InjectEventSecurityException

Android:如何使用 Espresso 测试按钮 bgcolor 在按下时是否发生了变化?

android - 关闭通知后打开应用程序主页

android - 警告 :Using incompatible plugins for the annotation processing: android-apt

java - Gradle同步失败: Build tools download failed with code 2

android - 使用单个命令从多模块项目运行所有 UI/单元测试

android - junit.framework.AssertionFailedError : Exception in constructor: (java. lang.NoClassDefFoundError)

JAVA - 单选按钮已选中

android - 列表项点击触发 subview 的选择器

java - 如何实现可折叠(带 handle )的垂直侧边栏android