微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运行connectedAndroidTest并跳过卸载

有没有办法调用任务connectedAndroidTest并在流程结束时跳过卸载任务?

在测试执行结束时,应用程序将从设备中卸载,但我希望将应用程序保留在设备上.

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-tests

As mentioned prevIoUsly, checks requiring a connected device are launched with the anchor task called connectedCheck. This depends on the task connectedDebugAndroidTest and therefore will run it. This task does the following:

  • Ensure the app and the test app are built (depending on assembleDebug and assembleDebugAndroidTest).
  • Install both apps.
  • Run the tests.
  • Uninstall both apps.

解决方法:

看看gradle插件的魔力,在测试任务结束时无法阻止卸载应用程序.你可以在android gradle插件的SimpleTestCallable类中检查一下.

从我看到有两个选项来实现你想要的.

首先是在完成连接检查后重新安装应用程序.执行此操作的命令看起来像这样. ./gradlew connectedCheck installDebug installDebugAndroidTest这将在设备上执行测试并从中删除应用程序.但之后它将重新安装应用程序和测试应用程序.所以应用程序仍然会被移除然后安装,这意味着有点owerhead但是至少应用程序不会被重新编译两次,因为你在同一个gradle执行中执行.

第二个选项是不使用gradle执行测试,而是使用adb.
要做到这一点,首先需要通过gradle安装app和test app.
./gradlew installDebug installDebugAndroidTest

之后,您可以通过adb执行测试.通过caling adb shell am instrument -w com.example.test / android.support.test.runner.AndroidJUnitRunner.

完成此操作后,您可以运行cli测试,因为仍然安装了app和test app.

使用第二种方法,您将失去执行测试机智的所有好处.例如代码覆盖和在多个过程中执行等.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐