简体   繁体   中英

Maven Surefire plugin executes JUnit 4 tests, even though the JUnit Vintage Engine is not in Maven the project

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM