Gradle test Unit tests - Run all except one or few - Command line

跟風遠走 提交于 2020-01-31 12:09:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!