Robolectric-Gradle plugin running single test

1.3k Views Asked by At

Is it possible to run single tests using Robolectric-Gradle plugin?

I tried with this:

./gradlew test -Dtest.single=testName

But it is not working.

2

There are 2 best solutions below

2
On BEST ANSWER

Made the same mistake myself. Thats the format for jcandksolutions plug-in (at least that's what I was using). -Dtest.single=<test name> is not supported by RoboE-Gradle plugin.

Use --tests <test class name> mechanism. This can be either --tests <classpath of test> or wildcard with --tests *.*Test

1
On

The method described in the original question does work but you must be working with the latest versions of the robolectric gradle plugin as per docs here

So currently in your dependencies section you'll need

classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'

If you are updating from 0.xx, as I was, you'll probably need to change the dependencies from androidTestCompile to testCompile to build your tests.

Then as above

./gradlew test -DtestDebug.single=<NameOfTestClass>

Will run just your single test (Notice it assumes your test class ends in *Test so you can skip it from the command)