不能使用Gradle按类别包含/排除Junit测试类 [英] Cannot include/exclude Junit tests classes by Category using gradle

查看:435
本文介绍了不能使用Gradle按类别包含/排除Junit测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定这些接口

Given these interfaces

testclient.priority.High
testclient.priority.Low

以及一个像这样注释的junit类

and a junit classes annotated like this

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

I试图在build.gradle中配置一个包含/排除模式,像这样

I tried to configure an include/exclude pattern in build.gradle like this

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

问题完全没有运行测试。准确的语法如何实现呢?
我使用gradle 2.14.1并通过clean build调用测试。

The problem is that no tests are run, at all. How is the exact syntax to achieve that? I am using gradle 2.14.1 and invoke the tests by "clean build".

推荐答案

我发现问题我。我错过了这个事实:

I found the problem myself. I missed the fact that

High extends Low

,因此排除操作正确地影响了所有注释测试。扩展是有意的,build.gradle中的正确模式可以简单地为:

so the exclusion correctly affected all annotated tests. The extension is intended and the correct pattern in build.gradle would simply be:

useJUnit {
    includeCategories 'testclient.priority.High'
}

实际上有五个优先级,扩展依赖是一个简单的方法来配置运行这个级别或更高级别的所有内容。

In fact there are five priority levels and the extension dependency is an easy way to configure something like "run everything of this level or higher".

这篇关于不能使用Gradle按类别包含/排除Junit测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆