Gradle test Unit tests - Run all except one or few

2020-06-18 09:33发布

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条回答
虎瘦雄心在
2楼-- · 2020-06-18 10:15

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
查看更多
登录 后发表回答