JUnit 5 TestSuite alternative?

Viewed 7872

I'm in the process of migrating from JUnit 4 to 5 and decided to rewrite all old @Tests to the new org.junit.jupiter.api.Test.

My goal is to drop the old junit4 dependency completely, only keeping these dependencies:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.0.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-runner</artifactId>
    <version>1.0.1</version>
    <scope>test</scope>
</dependency>

So far I've rewritten everything except my TestSuites, which I use to cluster all Tests into 4 separate suites, callable by the surefire plugin.

It seems that JUnit 5 has no declarative suite support at all, but does have the @Tag annotation.

Question:

How can I create some kind of testsuite-alternative with only JUnit 5 stuff, callable with the maven-surefire-plugin ( <includes> ) AND runnable IntelliJ?

1 Answers

Despite the rich junit-platform-suite-api, it's currently (June 2018) not possible, because native test suite support is not in the platform. Instead, you must use the junit-platform-runner which depends on junit-4.12.jar to identify and run suites.

@RunWith(JUnitPlatform.class)
@SelectClasses({Dog.class, Cat.class})
public class MyTestSuite {
}

However, native support might be coming in 1.3 version of the platform, according to this github issue.

I deleted all of my test suites to avoid having junit 4 in my projects at all. I will happily create them again using the new functionality when it's available.

Related