Run jUnit tests using @category spring and gradle

I need to run some integration tests and some unit tests, and I use spring, gradle and jUnit 4.

I used the jUnit @Category (UnitTestCategory.class) and @Category (IntegrationTestCategory.class) categories and I added

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

for gradle to include / exclude category. The idea is that I don’t want to mix unit tests and integration test, and I have a category for each of them.

The problem is that I have to use both spring and categories, and @RunWith(...) can only take one class param. - RunWith(SpringJUnit4ClassRunner.class) class param. - RunWith(SpringJUnit4ClassRunner.class) or @RunWith(Categories.class) .

I could not use @RunWith({Categories.class, SpringJUnit4ClassRunner.class}) , and I have to work with spring and categories. In addition, in the future I may need to add other classes not only spring and category. So I need some parameters for @RunWith (...)

https://docs.gradle.org/current/userguide/java_plugin.html

Does anyone have a solution?

+5
source share
1 answer

Instead of spring runner, you can use spring junit rules . Then, as a runner, you can use Categories

+3
source

Source: https://habr.com/ru/post/1237634/


All Articles