运行connectedAndroidTest并跳过卸载 [英] Run connectedAndroidTest and skip uninstall

查看:145
本文介绍了运行connectedAndroidTest并跳过卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to call the task connectedAndroidTest and skip the uninstall task at the end of the process ?

在执行测试的最后,该应用已从设备上卸载,但我希望将该应用保留在设备上.

At the end of the test execution, the app is uninstalled from the device, but I would like to keep the app on the device.

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

如前所述,需要名为connectedCheck的锚定任务启动了需要连接设备的检查.这取决于任务connectedDebugAndroidTest,因此将运行它.此任务执行以下操作:

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:

  • 确保已构建应用程序和测试应用程序(取决于assembleDebug和assembleDebugAndroidTest).
  • 安装两个应用程序.
  • 运行测试.
  • 卸载两个应用程序.
  • 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类中进行检查.

Looking at the sorce of gradle plugin there is no way to prevent uninstalling app at the end of test task. You can check that in SimpleTestCallable class of android gradle plugin.

根据我的见解,有两种选择可以满足您的需求.

From what i see there are two options to acchive what you want.

第一个是在完成连接检查后重新安装应用程序.执行此操作的命令如下所示. ./gradlew connectedCheck installDebug installDebugAndroidTest这将在设备上执行测试并从中删除应用程序.但是之后,它将重新安装应用程序并测试应用程序.因此,应用程序仍将被删除然后再安装,这意味着有些麻烦,但由于您在同一gradle执行中执行,因此至少不会对应用程序进行两次重新编译.

First one is to reinstall app after your connected check is done. Command to do that would look something like this. ./gradlew connectedCheck installDebug installDebugAndroidTest This will execute test on device and delete apps from it. But after that it will reinstall app and test app. So app will still be removed and then installed which means a bit of owerhead but at least apps will not be recompiled twice since you are executing in same gradle execution.

第二个选项是不使用gradle执行测试,而是使用adb. 为此,您首先需要安装应用程序并通过gradle测试应用程序. ./gradlew installDebug installDebugAndroidTest

Second option is to not use gradle for executing tests but use adb instead. To do this you first need to install app and test app through gradle. ./gradlew installDebug installDebugAndroidTest

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

After that you can execute tests through adb. by caling adb shell am instrument -w com.example.test/android.support.test.runner.AndroidJUnitRunner.

完成此操作后,由于仍安装了应用程序和测试应用程序,因此您可以运行cli测试.

When this is done you can run your cli tests since both app and test app are still installed.

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

With second approach you would lose all the benefits of executing test wit gradle. Such as code coverage and executing in multiple proceses, etc.

这篇关于运行connectedAndroidTest并跳过卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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