Search code examples
junit4junit5

How to configure with gradle running JUnit4 tests with categories using vintage engine of jupiter Junit5 platform


When we had only JUnit4 tests, we used

test {
    useJUnit{
        excludeCategories "SlowTests"
    }
}

Now migrating to JUnit5 and still having JUnit4 tests around, how do we use it in JUnitPlattform to let tests marked with a JUnit test category out?

test {
    useJUnitPlatform{
        // ???
    }
}

Solution

  • JUnit4's categories are mapped to tags according to the full class name of the category

    So the following should work:

    tasks.test {
        useJUnitPlatform {
            includeTags.add("com.acme.Example")
            // or the following to exclude the tag: includeTags.add("!com.acme.Example")
        }
    }