Reputation: 17326
I have bunch of JUnit unit tests in my projects. Build system is Gradle. OS: Windows/Linux.
Test (Unit tests) come free in Gradle i.e. if you run "gradle clean build" Gradle will also run "test" task (to run your Unit tests). I know how can I run all tests in a test folder, of a specific test at command line. Ex: See 23.13.3 and 23.13.4 sections in Gradle user guide: http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test
My question:
I want to run all tests except one or some. How can I do this in Gradle at command line (rather than using exclude(s) within test { ... } section in build.gradle or higher level .gradle file).
Upvotes: 12
Views: 9039
Reputation: 4588
If you want to exclude more than one test per command line, here an enhanced version of Mark's answer (testet in gradle 6.8.2):
if (project.hasProperty('excludeTests')) {
project.properties['excludeTests']?.replaceAll('\\s', '')?.split('[,;]').each {
exclude "${it}"
}
}
On the command line you can now specify more than one test for exclusion:
$ gradlew test -PexcludeTests="**/bar*, **/foo.SomeTest*"
The separator may be ";" or ",", with or without following space.
Upvotes: 3
Reputation: 13466
You could conditionally add an exclusion based on a property value.
test {
if (project.hasProperty('excludeTests')) {
exclude project.property('excludeTests')
}
}
You could then do something like this from the command line.
$ gradle -PexcludeTests=org.foo.MyTest build
Upvotes: 16