无法使用 Maven 执行 Junit5 测试
Unable to execute Junit5 tests using Maven
Maven 执行
mvn clean test
我正在尝试将 junit5
用于我的一个 Maven 项目,但无法在 test
阶段使用 -
执行单元测试
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
我得到的输出是-
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ utils ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
尝试实施@ 提到的解决方案以将依赖项更新为 -
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-api</artifactId>
<version>5.0.0-ALPHA</version><!--https://mvnrepository.com/artifact/org.junit/junit5-api -->
<scope>test</scope>
</dependency>
并将插件更新为 -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>surefire-junit5</artifactId>
<version>5.0.0-ALPHA</version><!--couldn't find this on the central though-->
</dependency>
</dependencies>
</plugin>
但输出保持不变。
问题 - 这个自定义提供程序是否不再受支持,或者是否有使用 maven
执行测试的任何解决方案, junit5
and/or junit5-api
目前?
注意 - 测试执行在 JUnit-4 上运行良好。
你应该像这样配置 maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
您只需要包含 junit-jupiter-api 工件,并且仅在您的依赖项部分的测试范围内:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
有关详细信息,请参阅 http://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven。
Edit - 来自相同的文档。
In order to have Maven Surefire run any tests at all, a TestEngine
implementation must be added to the runtime classpath.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
Maven 执行
mvn clean test
我正在尝试将 junit5
用于我的一个 Maven 项目,但无法在 test
阶段使用 -
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
我得到的输出是-
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ utils --- ------------------------------------------------------- T E S T S ------------------------------------------------------- Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
尝试实施@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-api</artifactId>
<version>5.0.0-ALPHA</version><!--https://mvnrepository.com/artifact/org.junit/junit5-api -->
<scope>test</scope>
</dependency>
并将插件更新为 -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>surefire-junit5</artifactId>
<version>5.0.0-ALPHA</version><!--couldn't find this on the central though-->
</dependency>
</dependencies>
</plugin>
但输出保持不变。
问题 - 这个自定义提供程序是否不再受支持,或者是否有使用 maven
执行测试的任何解决方案, junit5
and/or junit5-api
目前?
注意 - 测试执行在 JUnit-4 上运行良好。
你应该像这样配置 maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
您只需要包含 junit-jupiter-api 工件,并且仅在您的依赖项部分的测试范围内:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
有关详细信息,请参阅 http://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven。
Edit - 来自相同的文档。
In order to have Maven Surefire run any tests at all, a
TestEngine
implementation must be added to the runtime classpath.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
</dependency>
</dependencies>
</plugin>