1

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.

Luca Vitucci
  • 3,674
  • 4
  • 36
  • 60
  • 1
    It seems that it can be done with `includePatterns` with some hacking but not directly. – Opal Dec 18 '14 at 16:41

2 Answers2

4

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

  • 3
    Whenever I try running this I'm getting `Unknown command-line option '--tests'`, is there something I'm missing here? I'm using the RoboE-Gradle plugin (v 0.14.1) and running the command `./gradlew clean test --tests MyTest` – Gabriel Feb 17 '15 at 04:05
  • 2
    First of all, `-Dtest.single=` is the generic syntax to make Gradle define a JVM system property called `test.single`, i.e. `-D` is handled by Gradle itself, not by any plugin. Similarly, `--tests` is a command line option [provided by the Java plugin](https://docs.gradle.org/current/userguide/java_plugin.html#test_filtering), it's not an option to a task (Gradle tasks cannot take command line arguments). That said, the question is whether the Robolectric plugin supports the `-Dtest.single` or `--tests` snytax, and in my experience it does support both. – sschuberth Jul 30 '15 at 07:36
1

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)

  • And if you are running into trouble getting android studio to pick up your test classes after changing `androidTestCompile` to `testCompile` then this line will fix that up for you `androidTestCompile configurations.testCompile.dependencies` – Brett Cherrington Mar 12 '15 at 20:11