Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify @category in test task in gradle?

Tags:

junit

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.

like image 472
Skarab Avatar asked Aug 09 '12 08:08

Skarab


People also ask

What is Gradle test task?

Advertisements. The test task automatically detects and executes all the unit tests in the test source set., Once the test execution is complete, it also generates a report. JUnit and TestNG are the supported APIs. The test task provides a Test.

How do I run a single test file in Gradle?

In versions of Gradle prior to 5, the test. single system property can be used to specify a single test. You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest.


1 Answers

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

like image 107
Luca Tettamanti Avatar answered Sep 28 '22 04:09

Luca Tettamanti