1

I have migrated my junit 4 code to junit 5 with the below version dependencies.

 <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.3.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-runner</artifactId>
        <version>1.3.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-junit-jupiter</artifactId>
        <version>2.22.0</version>
        <scope>test</scope>
    </dependency>

One of my scripts uses the command

mvn -B verify -DforkCount=1 -DreuseForks=false

But the issue I am facing is after migrating to junit5 while running it skips the testcase.

I am using maven-surefire-plugin - version 2.22.0.

While running it just print the below line

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

I even tried the below configurations but no help

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <properties>
                <configurationParameters>
                    junit.jupiter.conditions.deactivate = *
                    junit.jupiter.extensions.autodetection.enabled = true
                    junit.jupiter.testinstance.lifecycle.default = per_class
                    junit.jupiter.execution.parallel.enabled = true
                </configurationParameters>
            </properties>
        </configuration>
    </plugin>
</plugins>

My maven version is 3.3.9

and does not run the test case. Any specific reason why I am facing this strange issue. The same test case with JUnit 4 earlier worked fine.

After further analysis what I found the command => mvn -B verify -DforkCount=1 -DreuseForks=false does not run the test case and skips them. But when i replace the same command with => mvn -B verify -DforkCount=1 -DreuseForks=true , it starts working. I understand that properties forkCount=1/reuseForks=true, which means that maven-surefire-plugin creates one new JVM process to execute all tests in one Maven module but want to know why it does not work with mvn -B verify -DforkCount=1 -DreuseForks=false command. Is any maven or maven helper version upgrade is required for Junit5 migration?

Mureinik
  • 252,575
  • 45
  • 248
  • 283
Sam
  • 600
  • 1
  • 6
  • 20
  • Which are the test's names? There is a name convention for tests, maybe could be that – Leviand Oct 16 '18 at 07:12
  • Possible duplicate of [Surefire is not picking up Junit 5 tests](https://stackoverflow.com/questions/36970384/surefire-is-not-picking-up-junit-5-tests) – melanzane Oct 16 '18 at 07:19
  • mvn -B verify -DforkCount=1 -DreuseForks=true works but mvn -B verify -DforkCount=1 -DreuseForks=false does not. Just wanted to understand any specific reason for the same. – Sam Oct 16 '18 at 09:21
  • @melanzane it's not a duplicate. It's a different specific issue - see [my answer](https://stackoverflow.com/a/52832399/2422776). – Mureinik Oct 16 '18 at 09:38

1 Answers1

2

This is a known bug in maven-surefire-plugin with JUnit 5.3[.1] and a configuration that uses forks but does not reuse them.

Upgrading to maven-surefire-plugin 2.22.1 (released last weekend, October 7th 2018) will solve the issue.

Mureinik
  • 252,575
  • 45
  • 248
  • 283
  • 1
    Thanks @Mureinik for the answer.It resolved my issue. You saved my day. Also thanks everyone for their responses. – Sam Oct 16 '18 at 10:14