【发布时间】:2018-11-22 21:58:18
【问题描述】:
我的 pom 中有以下 maven surefire 插件设置。 有时我可能想用更少的线程来运行测试。我希望有一种方法可以从 mvn 命令行设置它。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
<includes>
<include>com.Online.runner.Regression.ONLINE_Chrome_RunnerTest</include>
</includes>
</configuration>
</plugin>
当我尝试使用下面的命令时,它似乎不起作用。
mvn clean test -X -DthreadCount=1
通过调试器检查值表明已设置系统属性。但它似乎被忽略了。
[DEBUG] Setting system property [threadCount]=[1]
[DEBUG] parallel='methods', perCoreThreadCount=true, threadCount=5,
我的测试仍然并行运行。我究竟做错了什么?一定有办法在 Pom 中覆盖这个值?
编辑:似乎它完全忽略了 threadCount 值,即使是 POM 中设置的值。这个值是不是没有传递给依赖Junit47?
【问题讨论】:
-
首先为什么你定义了一个不需要的插件依赖surefire-junit47...除此之外我建议阅读文档maven.apache.org/surefire/maven-surefire-plugin/examples/…以及为什么你需要通过命令行更改此配置?
-
@khmarbaise 不确定为什么包含该插件。但由于这是我继承的一个项目,我不想为了以防万一而摆脱它。虽然如果你认为这可能是一个问题,我会删除它。我正在从云工具部署构建,可能并不总是有这么多线程的容量。因此,与其每次都重新编码分支和 pom,不如在运行时将其设置为变量会更容易。
-
@khmarbaise 看起来这个依赖被定义为强制surefire插件使用Junit而不是testng启动。看起来这个项目在某个时候改变了测试框架。不太理想