Search code examples
androidjunitandroid-instrumentation

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


Solution

  • 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