25

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

jellyBeans
  • 293
  • 2
  • 4
  • 12
  • Your question isn't clear enough. It would seem that your technical understanding limits you from understanding the cause of the problem. I'd suggest looking through a few tutorials and then coming back here with a more specific question. – Alex.F Apr 18 '16 at 15:57
  • @Alex.F Apologies, I agree that the question is a bit ambiguous. Basically, I am looking for a way to run only specific the tests in Jenkins jobs. If I was using Maven builds, I know that the there is a way to run specific tests using the tags (annotations). Is there a similar way for Gradle builds as well? – jellyBeans Apr 19 '16 at 08:49

2 Answers2

44

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.

denys
  • 6,834
  • 3
  • 37
  • 36
  • Thanks denys. I am getting the following error com.android.builder.testing.ConnectedDevice > No tests found.[Google Nexus 5 - 5.1.0 - API 22 - 1080x1920 - 5.1] FAILED No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations). :app:connectedDebugAndroidTest – jellyBeans Apr 20 '16 at 09:01
  • @jellyBeans check for the package name like `com.android.builder.testing`. It should be one of the packages you will get after you run this command `adb shell pm list instrumentation`. – denys Apr 20 '16 at 14:46
  • I think, this error was to do with the Emulator. When I use a different emulator, not seeing this error anymore. But, there is another exception which is occurring INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.company.project.SignUpScreeTest/android.support.test.runner.AndroidJUnitRunner} – jellyBeans Apr 20 '16 at 14:53
  • This is what I have got in my build.gradle file testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" – jellyBeans Apr 20 '16 at 14:55
  • Shouldn't it be `com.company.project.test`. Check the instrumented package after you run this command `adb shell pm list instrumentation` and copy it into gradle task command. – denys Apr 20 '16 at 15:29
  • I am not sure if I have to create a test package under com.company.project. When I run the SignUpTest manually from the IDE, the command it picked up was the following and the test was run successfully: adb shell am instrument -w -r -e debug false -e class com.company.project.SignUpScreenTest com.company.project.debug.test/android.support.test.runner.AndroidJUnitRunner – jellyBeans Apr 20 '16 at 16:12
  • you are right. I tried to run the test by creating a "test" package under com.company.project and the test ran fine :) Many thanks for the help. – jellyBeans Apr 21 '16 at 09:20
  • Glad that I could help you. It would be nice if you accept my answer as the right one. – denys Apr 21 '16 at 10:16
  • The link to googlesamples GitHub is out of date. This is no longer the documented way to run specific tests. Can you update your answer to explain the options used? In particular, what is `-P`? – Code-Apprentice Aug 28 '18 at 03:00
  • Hm. What is out of date man? I even not mentioned this but try to prove me that this is not one of the documented way to run the tests. Or link doesn't open official googlesamples github project?! And at the end, try to spend some time and research what -P means. Oh wait, probably it is custom argument or parameter as mentioned on linked page...! – denys Sep 05 '18 at 22:13
0

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

jellyBeans
  • 293
  • 2
  • 4
  • 12