I know how to run all the tests in a single class using Gradle.
gradle -Dtest.single=FooTest test
But if FooTest contains a particular test method of special interest and I want to run only that method, how would I do that if using JUnit? And TestNG? I know with maven you can do something like this in the case of JUnit:
mvn -Dtest='FooClass#testMethod1' test
For JUnit I tried
$ gradle test -Dtest.single='FooClass#testMethod1'
but that did not work. Nor does (I’m grasping)
$ gradle test -Dtest.single='FooClass.testMethod1'
I also had the need run single JUnit test methods from Gradle. I have created a small project on GitHub that demonstrates how to implement a custom JUnit single test method runner and how to integrate it with Gradle. There are examples for both single and multi-project Gradle builds.
FYI: it hasn’t received much attention, but I’ve submitted a pull request for this issue: https://github.com/gradle/gradle/pull/193. I thought I’d put a note here as well in case anybody else from google comes across this page and is looking for a solution.
I’ve been using this in a local build (branched off 1.7) for several weeks now and it works great. =)