简体   繁体   English

如何使用Gradle运行Categorized Junit测试?

[英]How to run Categorized Junit tests using Gradle?

My Question is similar to this question , but it refers to Gradle not Maven . 我的问题类似于这个问题 ,但它指的是Gradle not Maven

I have marked several tests within my project with the @Category annotation, and created my Test Suite (See below). 我在项目中使用@Category注释标记了几个测试,并创建了我的测试套件(见下文)。

How do I run this using Gradle? 如何使用Gradle运行它?

Test Suite: 测试套件:

@RunWith(Categories.class)
@Categories.IncludeCategory(MyTestSuite.class)
@Suite.SuiteClasses(ClassUnderTest.class)
public interface MyTestSuite {
}

I suppose, you need something like this, according to JUnit wiki : 根据JUnit wiki ,我想,你需要这样的东西:

Gradle's test task allows the specification of the JUnit categories you want to include and exclude. Gradle的测试任务允许指定要包含和排除的JUnit类别。

 test { useJUnit { includeCategories 'org.gradle.junit.CategoryA' excludeCategories 'org.gradle.junit.CategoryB' } } 

Configuration above is example of global tests configuration, but you can create a custom test task to run specific test categories, as follows: 上面的配置是全局测试配置的示例,但您可以创建自定义测试任务来运行特定的测试类别,如下所示:

task customTest(type: Test) {
    useJUnit {
        includeCategories 'some.package.name.MyTestSuite'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM