Skip to content
Advertisement

JUnit 5 and Test Suites

We have a pure JUnit-5 project and we want to categories our unit tests.

To do so, what I understand is we need to include the JUnit-4 @RunWith(JUnitPlatform.class).

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@SelectPackages("my.project.domain")
@IncludeTags("long-running-test") 
public interface LongRunningTestSuite {}

In Intellij-Idea I can run all or just test suites without problems but I get an error on the execution with maven:

  • in Intellij-Idea some test cases fail
  • on the console I have an endless loop

This didn’t help:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <skip>false</skip>
        <excludes>
            <exclude>**/*TestSuite.java</exclude>
        </excludes>
        <includes>
            <include>**/*Test.java, **/*IT.java</include>
        </includes>
    </configuration>
</plugin>

If I just remove all the XyzTestSuite.java classes the maven build is successful. I also tried <exclude>my.project.domain.testsuite</exclude>.

The exclution seams not to work. Why?

Advertisement

Answer

JUnitPlatform has been deprecated.

The corresponding new feature is the JUnit Platform Suite Engine: https://junit.org/junit5/docs/current/user-guide/index.html#junit-platform-suite-engine

However, if it’s just about categorising tests, tags, which are much simpler, might be sufficient: https://junit.org/junit5/docs/current/user-guide/index.html#writing-tests-tagging-and-filtering

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement