我需要用控制台的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 –