9

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?

Bossk
  • 707
  • 8
  • 24
  • 1
    Have you seen test suites in JUnit5? This could be one possible solution if I am understanding correctly what you are trying to achieve. Here is a link: http://junit.org/junit5/docs/current/user-guide/#running-tests-junit-platform-runner-test-suite – Kotse Oct 09 '17 at 05:48
  • Although a bit clunky, you could define four Maven profiles and maintain your lists of classes or naming patterns there. – Marc Philipp Jun 23 '18 at 11:11
  • @Kotse I know I am late to the party but that documentation clearly says you cannot use JUnit5 tests. It will only run J4 tests (surely in 'vintage' mode). – Dilapidus May 16 '20 at 20:33
  • Does this answer your question? [Are test suites considered deprecated in JUnit5?](https://stackoverflow.com/questions/50565724/are-test-suites-considered-deprecated-in-junit5) – Mahozad Sep 13 '21 at 19:32

1 Answers1

6

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.

Community
  • 1
  • 1
John Churchill
  • 342
  • 4
  • 11