[英]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.我有一个包含 JUnit 4 和 JUnit 5 测试的 Maven 项目。
I am using the Maven Surefire plugin in version 3.0.0-M07
.我在3.0.0-M07
版本中使用 Maven Surefire 插件。 The following relevant dependencies are available in the Maven dependency tree (I checked with mvn dependency:tree
): Maven 依赖树中提供了以下相关依赖项(我检查了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. 根据 JUnit 5 文档,需要存在 JUnit Vintage Engine 才能执行 JUnit 4 测试。
However, the Maven Surefire plugin executes both the JUnit 4 and JUnit 5 tests.但是,Maven Surefire 插件同时执行 JUnit 4 和 JUnit 5 测试。
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?为什么 Maven Surefire 插件能够执行 JUnit 4 测试,即使在我的 Maven 项目中不依赖于 JUnit Vintage Engine?
By using junit-jupiter-api
maven-surefire-plugin/maven-failsafe-plugin loads the junit-vintage-engine
automatically and executes JUnit 4 based tests.通过使用junit-jupiter-api
maven-surefire-plugin/maven-failsafe-plugin 自动加载junit-vintage-engine
并执行基于 JUnit 4 的测试。
The correct way is to use the junit-jupiter-engine
instead of junit-jupiter-api
.正确的方法是使用junit-jupiter-engine
而不是junit-jupiter-api
。 This is explained in the surefire documentation这在surefire文档中进行了解释
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.