Is there a way to run a specific Android instrumentation unit test using Gradle? I\'ve tried
gradle -Dtest.single=UnitTestName connectedInstrumentTest
Erdi's answer didn't work for me but I have a single parent for all my test classes so I was able to do this:
public abstract class BaseEspressoTest extends ActivityInstrumentationTestCase2 {
//...
@Override
protected void runTest() throws Throwable {
if(getClass().getSimpleName().equals("MyTestClassName")) {
super.runTest();
}
}
//...
}
This executes only MyTestClassName. We can extend it further to execute only specific test method (or methods):
public abstract class BaseEspressoTest extends ActivityInstrumentationTestCase2 {
//...
@Override
protected void runTest() throws Throwable {
if("MyTestClassName".equals(getClass().getSimpleName())
&& "testMethodName".equals(getName())) {
super.runTest();
}
}
//...
}