运行 connectedAndroidTest 并跳过卸载

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

问题描述

限时送ChatGPT账号..

有没有办法调用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).
  • 安装这两个应用.
  • 运行测试.
  • 卸载这两个应用程序.

推荐答案

看gradle插件的源头,没有办法防止在测试任务结束时卸载app.您可以在 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 并跳过卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:Xcode 7:应用程序测试和 UI 测试之间的鸿沟是不可 下一篇:如何在 Espresso 测试失败时截取屏幕截图?

相关文章

最新文章