jellyBeans
jellyBeans

Reputation: 303

connectedAndroidTest how to run specific tests

I am a QA with a start up company. My Developer setup Instrumentation tests in the Android Project. He also setup the Jenkins Jobs to run these tests in CI env.

This is the command given in "Tasks" field in Jenkins job under Build --> Invoke Gradle script. clean assembleDebug connectedAndroidTest testDebug

I would like to create my own Jenkins job to run different types of tests. Is there a way that I can filter my tests by just running "connectedAndroidTest" command? I tried using shell script like the following, but it didn't work. adb shell am instrument -w /

I am getting the following error message: [Execute Smoke Test Suite] $ /bin/bash -xe /var/folders/qr/vtm32_d56vz0hgwg5ppdbswc00007q/T/hudson1779650135635362469.sh + adb shell am instrument -w ' ' class com.draysonwireless.airmapandroid.rewards/BonusTest.java /var/folders/qr/vtm32_d56vz0hgwg5ppdbswc00007q/T/hudson1779650135635362469.sh: line 2: adb: command not found Build step 'Execute shell' marked build as failure Finished: FAILURE

Upvotes: 26

Views: 11753

Answers (2)

jellyBeans
jellyBeans

Reputation: 303

This is the shell script I used in my Jenkins job:

export PATH=$PATH:/Users/Shared/Jenkins/Library/Android/sdk/platform-tools
adb shell am instrument -w -r   -e debug false -e class com.company.project.test.SmokeTest com.company.project.debug.test/android.support.test.runner.AndroidJUnitRunner

The folder structure should be as below: app --> src--> androidTest --> java --> com.company.project --> test --> TestClass

Upvotes: 0

denys
denys

Reputation: 6910

Seems that your jenkins user can't see android adb therefore build fails. Add adb to the system path or point it's exact location.

As to running specific tests via gradle command below is an example:

./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.android.testing.blueprint.ui.espresso.EspressoTest#testMethodName

Taken from here with my slight modification. Your connectedAndroidtest command can vary depending on the test flavour existence.

Upvotes: 48

Related Questions