我需要用控制檯的gradle執行某些Android測試用例(類或方法)。 它位於src/androidTest/java/com/example/CertainTest.java。用gradle運行特定的Android測試
Android Studio通過複雜的adb shell am instrument
提供此功能。
是否可以通過Gradle調用某些Android測試?
我已經閱讀了關於How to run only one test class on gradle,Test from the Command Line,但它是相當複雜的做法。
這是Android的工作室是如何啓動的具體測試類:
Launching Tests
$ adb push /.../app/build/outputs/apk/app-debug.apk /data/local/tmp/com.example.andrii.espressotutorial
$ adb shell pm install -r "/data/local/tmp/com.example.andrii.espressotutorial"
pkg: /data/local/tmp/com.example.andrii.espressotutorial
Success
$ adb push /.../app/build/outputs/apk/app-debug-androidTest.apk /data/local/tmp/com.example.andrii.espressotutorial.test
$ adb shell pm install -r "/data/local/tmp/com.example.andrii.espressotutorial.test"
pkg: /data/local/tmp/com.example.andrii.espressotutorial.test
Success
Running tests
$ adb shell am instrument -w -r -e debug false -e class com.example.andrii.espressotutorial.ExampleInstrumentedTest2 com.example.andrii.espressotutorial.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.
也許只是將這些adb命令包裝到自定義gradle任務中。 – WenChao
檢查這個問題 https://stackoverflow.com/questions/21288448/how-to-retrieve-path-to-adb-in-build-gradle –