Problem running JUnit5 tests with Maven Surefire

Hello.

I’m trying to run my unit tests written with JUnit5 with maven.

I have configured relevant pom.xml sections like this :

  • dependencies :
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
       </dependency>
  • surefire configuration :
         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>${junit-jupiter.version}</version>
                    </dependency>
                </dependencies>
          </plugin>

Also I’m using junit jupiter version 5.6.0.

Now when I run mvn test following error occurs :

[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-jupiter' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] TestEngine with ID 'junit-jupiter' failed to discover tests
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:656)
…

I’ve tried several of the solutions found online but with no luck. Does anybody know what to do with this ? I really need to make this work as I want to set up a CI/CD pipeline for my plugin.

Any useful information will be greatly appreciated. If needed I can provide full pom.xml listing.

Thanks in advance.
Cheers.

Hi @MaciejWikira,

have a look at https://github.com/viqueen/devbox/tree/master/confluence-devbox
The project uses JUnit5 and should help you getting started

1 Like

Thank you. Using your repo as a reference I’ve managed to fix my code.

What I’ve done is :

  • removed this
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <!-- Disable unit tests-->
                    <skip>true</skip>
                </configuration>
            </plugin>
  • removed this
<dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>
  • and removed this
<dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </dependency>
  • execute mvn clean, mvn compile, mvn test-compile (that was needed because for some reason tests couldn’t pick up necessary classes from my plugin’s package)

I guess I got a little confused with how to properly use JUnit5 modules. Also I think redundant dependency on maven surefire artifact was messing up my environment. Anyway, now mvn test works properly.

Thank you once more @dennis.fischer .
Cheers.