Gradle:如何排除一些测试?

我的src/test/文件夹包括单元和function测试。 function测试的类路径使用单词cucumber ,而unit testing则没有。 那么,我怎样才能运行unit testing呢?

非常感谢你。

PS :我知道使用“包含”逻辑来选择测试很容易。 例如,要仅在我的情况下运行function测试,我可以简单地使用它
./gradlew test -Dtest.single=cucumber/**/
但是,我不知道如何以简单的方式排除测试。

顺便说一下,我正在使用gradle 1.11。

该任务的文档解释了它,并举例说明了一切:

 apply plugin: 'java' // adds 'test' task test { // ... // explicitly include or exclude tests include 'org/foo/**' exclude 'org/boo/**' // ... } 

信用 :这个答案的灵感来自JB Nizet的回答。 它被发布是因为它更直接我的问题。

要仅运行unit testing,请创建一个如下所示的新任务:

 task unitTest( type: Test ) { exclude '**/cucumber/**' } 

这样我们就有:
运行所有测试: ./gradlew test
运行所有unit testing: ./gradlew unitTest
运行所有function测试: ./gradlew test -Dtest.single=cucumber/**/

您可以根据外部系统属性将其排除。

 -Dtest.profile=integration 

并在build.gradle中

 test { if (System.properties['test.profile'] != 'integration') { exclude '**/*integrationTests*' } }