java123999
java123999

Reputation: 7394

How to run Categorized Junit tests using Gradle?

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 {
}

Upvotes: 6

Views: 1777

Answers (1)

Stanislav
Stanislav

Reputation: 28106

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'
    }
}

Upvotes: 3

Related Questions