android 运行跳过方法,运行connectedAndroidTest并跳过卸载

博客探讨了调用任务connectedAndroidTest后跳过卸载任务的方法。测试结束时应用会被卸载,可通过两种方式保留应用:一是完成连接检查后重新安装;二是不使用gradle,先用gradle安装应用,再用adb执行测试,但会失去一些执行测试的好处。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

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.

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

标签:android,gradle,android-gradle,automated-tests

来源: https://codeday.me/bug/20190622/1263532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值