有没有办法调用任务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