无法使用Maven执行Junit5测试

Maven执行

mvn clean test 

我正在尝试将junit5用于我的一个maven项目,但是在test阶段无法使用 – 执行unit testing –

  org.junit.jupiter junit-jupiter-api 5.0.0-M3  

我得到的输出是 –

 [INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ utils --- ------------------------------------------------------- TESTS ------------------------------------------------------- Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

尝试实施提到的解决方案@ Surefire没有采用Junit 5测试来更新依赖关系 –

  org.junit.jupiter junit-jupiter-api 5.0.0-M3   org.junit junit5-api 5.0.0-ALPHA test  

并将插件更新为 –

  org.apache.maven.plugins maven-surefire-plugin 2.19.1   org.junit surefire-junit5 5.0.0-ALPHA    

但输出仍然相同。

问题 – 这个自定义提供程序是否不再受支持,或者目前使用mavenjunit5和/或junit5-api执行测试是否有任何解决方案?

– 测试执行与JUnit-4一起正常工作。

您应该像这样配置maven-surefire-plugin:

  org.apache.maven.plugins maven-surefire-plugin 2.19.1   org.junit.platform junit-platform-surefire-provider 1.0.0-M3    

您只需要包含junit-jupiter-api工件,并且只能包含在依赖项部分的测试范围中:

  org.junit.jupiter junit-jupiter-api 5.0.0-M3 test  

有关更多信息,请参阅http://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven 。

编辑 – 来自相同的文档。

为了让Maven Surefire运行任何测试,必须将TestEngine实现添加到运行时类路径中。

  maven-surefire-plugin 2.19   org.junit.platform junit-platform-surefire-provider 1.0.0-M3   org.junit.jupiter junit-jupiter-engine 5.0.0-M3