Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jUnit tests using @category spring and gradle

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

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

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

for gradle in order to include/exclude a 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 must use both spring and categories and @RunWith(...) can receive only one class param. - RunWith(SpringJUnit4ClassRunner.class) or @RunWith(Categories.class) .

I couldn't use @RunWith({Categories.class, SpringJUnit4ClassRunner.class}) and I must run with spring and categories. Plus that in the future i might need to add also other classes not only spring and category. So i need multiple parameters for @RunWith(...)

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

Does anyone have a solution please?

like image 532
MyUserQuestion Avatar asked Oct 19 '22 20:10

MyUserQuestion


1 Answers

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

like image 159
piotrek Avatar answered Oct 27 '22 11:10

piotrek