我目前正在尝试将 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 任务 assembleDebug
和 assembleDebugAndroidTest
与 Espresso 一起工作。但是,由于没有 assembleReleaseAndroidTest
任务,发布版本在做什么?
提前感谢您的建议!
最佳答案
您无法将测试编译到应用 APK 中,但您可以针对发布构建类型进行测试。在您的情况下,您的发布 Artifact 将包含两个 APK,即常规应用 APK 和测试 APK。参见 https://stackoverflow.com/a/18064368/1231827 .
关于android - 如何将 Espresso UI 测试编译成一个版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221034/