5

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?

MyUserQuestion
  • 295
  • 1
  • 9
  • 1
    You don't have to use `@RunWith(Categories.class)` if you run your tests with Gradle. The `Categories` runner is only needed if you want to use a special Suite that you can start in your IDE. – Stefan Birkner Dec 08 '15 at 10:25
  • Yes but i i have two test categories integration tests and unit tests and i don't want to mix them. I want to run only one category using includeCategories / excludeCategory in gradle. – MyUserQuestion Dec 08 '15 at 11:38

1 Answers1

3

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

user229044
  • 232,980
  • 40
  • 330
  • 338
piotrek
  • 13,982
  • 13
  • 79
  • 165