問題描述
有沒有辦法調用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模板網!