Home > Blockchain >  Maven Surefire plugin executes JUnit 4 tests, even though the JUnit Vintage Engine is not in Maven t
Maven Surefire plugin executes JUnit 4 tests, even though the JUnit Vintage Engine is not in Maven t

Time:06-21

I have a Maven project that contains both JUnit 4 and JUnit 5 tests.

I am using the Maven Surefire plugin in version 3.0.0-M07. The following relevant dependencies are available in the Maven dependency tree (I checked with mvn dependency:tree):

  • org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
  • org.junit.platform:junit-platform-commons:jar:1.8.2:test
  • org.junit.jupiter:junit-jupiter-params:jar:5.8.2:test
  • junit:junit:jar:4.13.2:test

According to the JUnit 5 documentation, the JUnit Vintage Engine needs to be present to execute JUnit 4 tests.

However, the Maven Surefire plugin executes both the JUnit 4 and JUnit 5 tests.

Why is the Maven Surefire plugin able to execute JUnit 4 tests, even though there is no dependency on the JUnit Vintage Engine in my Maven project?

CodePudding user response:

By using junit-jupiter-api maven-surefire-plugin/maven-failsafe-plugin loads the junit-vintage-engine automatically and executes JUnit 4 based tests.

The correct way is to use the junit-jupiter-engine instead of junit-jupiter-api. This is explained in the surefire documentation

An deep explanation is available here.

  • Related