问题
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).
回答1:
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
来源:https://stackoverflow.com/questions/26809485/gradle-test-unit-tests-run-all-except-one-or-few-command-line