无法使用 gradle 按类别 include/exclude Junit 测试 类

Cannot include/exclude Junit tests classes by Category using gradle

给定这些接口

testclient.priority.High
testclient.priority.Low

和一个像这样注释的 junit 类

@Category(testclient.priority.High.class)
public class MyTest {
...
}
@Category(testclient.priority.Low.class)
public class MyOtherTest {
...
}

我试过像这样在 build.gradle 中配置 include/exclude 模式

useJUnit {
    includeCategories 'testclient.priority.High'
    excludeCategories 'testclient.priority.Low'
}

问题是根本没有测试 运行。实现这一目标的确切语法是什么? 我正在使用 gradle 2.14.1 并通过 "clean build".

调用测试

这适用于 Gradle 2.12。我不知道我们各自的环境有什么不同,但是我放了my solution on GitHub以供参考。

请注意,我已将 FastTest.javaSlowTest.java 放在测试所在的 src/test/java/net/codetojoy 文件夹中。

我自己发现了问题。我错过了

High extends Low

所以排除正确地影响了所有带注释的测试。扩展是有意的, build.gradle 中的正确模式只是:

useJUnit {
    includeCategories 'testclient.priority.High'
}

实际上有五个优先级,扩展依赖是配置类似 "run everything of this level or higher".

的简单方法