How to run Categorized Junit tests using Gradle?
Asked Answered
T

1

6

My Question is similar to this question, but it refers to Gradle not Maven.

I have marked several tests within my project with the @Category annotation, and created my Test Suite (See below).

How do I run this using Gradle?

Test Suite:

@RunWith(Categories.class)
@Categories.IncludeCategory(MyTestSuite.class)
@Suite.SuiteClasses(ClassUnderTest.class)
public interface MyTestSuite {
}
Talbert answered 14/11, 2016 at 12:4 Comment(0)
S
3

I suppose, you need something like this, according to JUnit wiki:

Gradle's test task allows the specification of the JUnit categories you want to include and exclude.

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'
    }
}
Saloma answered 14/11, 2016 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.