Harold L. Brown
Harold L. Brown

Reputation: 9946

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):

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?

Upvotes: 0

Views: 1302

Answers (1)

khmarbaise
khmarbaise

Reputation: 97349

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.

Upvotes: 3

Related Questions