Prem
Prem

Reputation: 3543

How can I run a single android instrumentation test case?

Not a unit test, but an instrumentation test.

My app has multiple flavors, so I run:

./gradlew connectedClientDebugAndroidTest to run my instrumentation tests (flavor name is client).

But I want to run one particular instrumentation test case class called MyActivityTestCase.java. Is this possible? If it is what is the command to run this

Upvotes: 1

Views: 1910

Answers (3)

Prem
Prem

Reputation: 3543

So the way I fixed this was by putting the single TestCase that I want into a specific folder by flavor.

  • So in this example, my flavor is named client, so I put the single test that I want to run for this flavor into app/src/androidTestClient/MyActivityTestCase.java
  • Then run ./gradlew connectedClientDebugAndroidTest

Not a solution if you have multiple test cases for a specific build flavor, but for me that wasn't the case so it works.

  • All my other tests are in my flavor called other, in the folder: app/src/androidTestOther/. So to run the other instrumentation tests I just run the command ./gradlew connectedOtherDebugAndroidTest

Upvotes: 0

Code-Apprentice
Code-Apprentice

Reputation: 83527

With Gradle, you can run a single test by using the test.single system property. You set it from the command-line with the -D option. For example

$ gradle -Dtest.single=MyActivityTestCase connectedClientDebugAndroidTest

For more details, see http://mrhaki.blogspot.com/2013/05/gradle-goodness-running-single-test.html.

Upvotes: 1

ap6491
ap6491

Reputation: 835

The general syntax using adb shell is :

adb shell am instrument -w <test_package_name>/<runner_class>

where is the Android package name of your test application, and is the name of the Android test runner class you are using.

More details at: http://developer.android.com/tools/testing/testing_otheride.html

Upvotes: 0

Related Questions