14

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.

Community
  • 1
  • 1
Skarab
  • 6,981
  • 13
  • 48
  • 86
  • ps. It was much easier to put integration-test in a separate directory: src/integration-test/. This approach makes also the separation of the tests much easier to maintain and follow by team members. – Skarab Aug 25 '12 at 15:40

2 Answers2

35

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

Luca Tettamanti
  • 10,314
  • 3
  • 29
  • 25
  • 1
    Worked for me, thanks! I've used this approach for splitting Unit and Integration tests and also introduced a separate task to run Integration tests separately. – Vladimir Salin Sep 02 '16 at 21:02
-1

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

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259