Gradle test Unit tests - Run all but one or more - Command line

I have a bunch of JUnit unit tests in my projects. Gradle build system. OS: Windows / Linux.

The test (unit tests) is freed in Gradle, that is, if you run the " gradle clean build " Gradle, the "test" task will also be launched (to run your unit tests). I know how I can run all the tests in the test folder of a specific test on the command line. Example: see Sections 23.13.3 and 23.13.4 in the Gradle user guide: http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test

My question is:

I want to run all the tests except one or more. How can I do this in Gradle on the command line (instead of using the exceptions in the test {...} section in the build.gradle file or higher.).

+4
source share
1 answer

You can conditionally add an exception based on the value of the property.

test {
    if (project.hasProperty('excludeTests')) {
        exclude project.property('excludeTests')
    }
}

Then you can do something similar from the command line.

$ gradle -PexcludeTests=org.foo.MyTest build
+7
source

All Articles