I need to execute certain Android test case (Class or method) with gradle from console. It is located at src/androidTest/java/com/example/CertainTest.java.
Android Studio makes this available via complicated adb shell am instrument
.
Is it possible to invoke certain Android Test only via Gradle?
I have read about How to run only one test class on gradle, Test from the Command Line but is it quite complicated way of doing that.
This is how Android Studio launches specific Test Class:
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.