San Kh
San Kh

Reputation: 175

android espresso: running test from command line

I have a test.espresso package with all the test classes. I am trying to run a single test class from the command line, however it ends up running all the test classes.

adb shell am instrument -w \ com.demo.app.test/android.support.test.runner.AndroidJUnitRunner

How do I just run a single test class. I want to use bamboo(which is like jenkins) to run all the test classes individually in separate jobs.

Upvotes: 4

Views: 23492

Answers (4)

crgarridos
crgarridos

Reputation: 9263

I'm adding also how to run it from Gradle here.

./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.MyClassTest#myFunctionTest

Upvotes: 4

user846316
user846316

Reputation: 6331

If you're using gradle, then there is gradle task you can directly use to achieve it. It would be something like this:

./gradlew connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.

To run on specific flavor:

./gradlew connectedMyAppFlavorDebugAndroidTest

It does everything for you, right from building the app, installing on the connected device, run the tests and finally uninstall the app.

If you're not sure about the exact gradle task you need to execute the tests, run the following to get the all available gradle tasks:

./gradlew tasks

You'll get the list of all the tasks with the short description.

Upvotes: 8

MakerModder
MakerModder

Reputation: 1571

To run via command line

Start device. I use Genymotion so I would do

gmtool admin start DeviceName

Install via command line

For ADB

for ADB is should be exactly what the console outputs from Android studio when you start .

$ adb push /Users/x/x-android/app/build/outputs/apk/x-debug.apk 
$ adb shell pm install -r "/data/local/tmp/com.x"

$ adb push /x/x/x-android/app/build/outputs/apk/x-debug-androidTest.apk /data/local/tmp/com.x.test
$ adb shell pm install -r "/data/local/tmp/com.x.test"

For Genymotion it is

gmtool device install ~/Desktop/x.apk 
gmtool device install ~/Desktop/x-androidTest.apk 

For Genymotion connect Genymotion to ADB

gmtool device adbconnect


Start your tests. This is for both ADB and Geny

adb shell am instrument -w -r   -e debug false -e class com.x.MyTest com.x.test/android.support.test.runner.AndroidJUnitRunner

Upvotes: 2

Dr. Nitpick
Dr. Nitpick

Reputation: 1712

This worked for me (the change is in bold:

adb shell am instrument -w-e class full.path.and.TestClassName\ com.demo.app.test/android.support.test.runner.AndroidJUnitRunner

Based on: https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax (look under options for "class").

Upvotes: 8

Related Questions