使用Gradle运行UI自动化测试,无需卸载 [英] Run UI automation tests with gradle without uninstalling

查看:214
本文介绍了使用Gradle运行UI自动化测试,无需卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Android Studio中运行检测测试时,我发现应用程序保留在设备上。但我无法想象从gradlew的命令行做到这一点。我的目的是在eg / data / data / MyApp / cache / screenshots下运行测试并保存截图,然后用 adb pull 下载。

When I run instrumentation tests from within Android Studio, I see that the app remains on the device afterwards. But I can't figure out to do this from the command line with gradlew. My intention is to run tests that save screenshots in e.g /data/data/MyApp/cache/screenshots and download these with adb pull afterwards.

./gradlew connectedAndroidTest

原因要卸载的应用程序。我也试过了

causes the app to be uninstalled. I also tried

./gradlew connectedAndroidTest -x uninstallAndroidTest

但没有任何区别。什么是导致卸载,我怎么能避免它?

but that didn't make any difference. What's causing the uninstallation, and how can I avoid it?

推荐答案

我通过让gradle只生成apk来解决这个问题,然后使用adb处理安装/测试/卸载工作。这是我的脚本的近似值。

I solved this by letting gradle only build the apk, and then handling the install/test/uninstall work with adb. Here's an approximation of my script.


PKGNAME=com.corp.app
./gradlew assembleAndroidTest
adb install -r app/build/outputs/apk/app-debug.apk
adb install -r app/build/outputs/apk/app-debug-androidTest-unaligned.apk

adb shell am instrument -w ${PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner

[ -d screenshots ] || mkdir screenshots
adb pull /data/data/${PKGNAME}/cache/screenshots screenshots

# Now we can uninstall.
adb uninstall ${PKGNAME}.test
adb uninstall ${PKGNAME}

这篇关于使用Gradle运行UI自动化测试,无需卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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