首页 > 解决方案 > 如何让 Maven Surefire 退出当前正在寻找测试的位置?

问题描述

当我无法正确找到我的路径时,我从 Maven Surefire 获取以下日志。有没有办法让它吐出testSourceDirectory设置的目录?

[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ project ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.549 s
[INFO] Finished at: 2018-08-02T19:31:08-04:00
[INFO] ------------------------------------------------------------------------

我的 pom.xml

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.22.0</version>
   <configuration />
   <dependencies>
      <dependency>
         <groupId>org.junit.platform</groupId>
         <artifactId>junit-platform-surefire-provider</artifactId>
         <version>1.2.0</version>
      </dependency>
   </dependencies>
</plugin>

我的源代码在src/main/java/org/company/project.

我的测试在src/test/java/org/company/project

我用来设置 pom.xml 的教程:https ://howtoprogram.xyz/2016/09/09/junit-5-maven-example/

我可以在这个项目中使用这个 pom.xml 成功运行测试:https ://github.com/junit-team/junit5-samples/tree/r5.2.0/junit5-jupiter-starter-maven 。但是当我将它转移到我自己的项目中时,它无法获得任何规范。

编辑:显然我们正在使用spring-boot-starter-test,它只使用 JUnit 4。使用https://info.michael-simons.eu/2018/06/18/maven-use-junit-5-with-spring-boot-for-unit- and-integration-tests/看看我是否可以使用 JUnit 5。

标签: mavenmaven-surefire-plugin

解决方案


运行测试时,尝试将 -X 参数添加到 maven

mvn -X test

并查找您要询问的参数。在我的环境中,它的价值是

[DEBUG]   (s) testSourceDirectory = C:\Users\ME\MyWork\workspace\MyProject\src\test\java

希望这可以帮助。


推荐阅读