gpt4 book ai didi

multithreading - Maven:如何为testng设置线程数

转载 作者:行者123 更新时间:2023-12-03 12:47:01 24 4
gpt4 key购买 nike

我正在使用 testng 并行运行测试。 Xml 文件包含线程计数参数。

<suite name="Lalala" parallel="tests" thread-count="3" preserve-order="true">

但我想从 POM 文件中设置线程计数值。我试过了

    <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
</dependency>

    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/${suite}.xml</suiteXmlFile>
</suiteXmlFiles>
<workingDirectory>target/</workingDirectory>
</configuration>
</plugin>

但线程数仍然等于 1

有什么方法可以从 Pom 文件中添加线程数吗??

最佳答案

  1. 您可能需要从 XML 文件中的套件定义中删除 thread-count,因为它将覆盖 Maven Surefire 传递给 TestNG 的任何 -threadcount 参数(请参阅命令行参数Running TestNG 下)。
  2. 从本地测试看来 threadCountsuiteXmlFiles不兼容,来自 suiteXmlFiles 的 Maven Surefire 插件文档指出:

    Note that suiteXmlFiles is incompatible with several other parameters of this plugin, like includes/excludes.

    我相信 threadCount 是另一个不兼容的“其他参数”。

    TestNG XML 文件中可用的一些相同选项在配置 Maven Surefire 插件时也可用,因此看起来您必须将 TestNG XML“移植”到 Maven Surefire 插件配置 XML。

    在我的本地测试中,我发现我可以简单地省略 suiteXmlFiles,插件会找到并使用指定的 threadCount 运行我的测试。根据您的 TestNG XML,您的解决方案可能需要更多工作。

关于multithreading - Maven:如何为testng设置线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com