Skarab
Skarab

Reputation: 7141

How to specify @category in test task in gradle?

I would like to learn whether I can specify the @category in gradle test task. So, I can run separately integration junits and the normal junit tests.

I know that there is currently no explicit support for @category in gradle and I am looking for a workaround for this limitation.

The straightforward approach is to define test suits for different test categories, e.g., How to run all tests belonging to a certain Category in JUnit 4. I would prefer to specify @category in my gradle script.

Upvotes: 14

Views: 10224

Answers (2)

Luca Tettamanti
Luca Tettamanti

Reputation: 10614

Support for including or excluding categories has been included in gradle:

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

Full documentation: https://docs.gradle.org/current/userguide/java_testing.html#test_grouping

Upvotes: 35

Peter Niederwieser
Peter Niederwieser

Reputation: 123920

I don't think there is a solution other than implementing the feature or using test suites. Feel free to file a feature request at: http://forums.gradle.org

Upvotes: -1

Related Questions