【问题标题】:Maven: how to set thread count for testngMaven:如何为 testng 设置线程数
【发布时间】:2015-12-23 08:57:02
【问题描述】:

我正在使用 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 文件中添加线程数??

【问题讨论】:

    标签: multithreading maven testng maven-surefire-plugin


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

      请注意,suiteXmlFiles 与此插件的其他几个参数不兼容,例如 includes/excludes

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

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

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

    【讨论】:

    • @N.Kuznetsov 我已经更新了我的答案。 threadCountsuiteXmlFiles 似乎彼此不兼容。
    • threadCount 优先级不正确。我的 pom.xml 中的值优先于提供的运行时值。可能是一个错误
    【解决方案2】:

    我不尝试这样做,但这种配置应该可以工作。 我不确定,但要使用它,您应该使用版本 2.19+ 的 surefire 插件。另外,我建议您在使用 TestNG 时不要在部分(如 等)中使用特定于 Surefire 的元素名称。更好的选择是使用带有一组 值的 部分。这些值将传递给 testNG 命令行。 TestNG documentation

    中清楚地描述了此类属性的行为
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-testng</artifactId>
                <version>2.19</version>
            </dependency>
        </dependencies>
    
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>suites/my-suite.xml</suiteXmlFile>
            </suiteXmlFiles>
    
        <!-- DONT USE THIS
        <parallel>methods</parallel>
        <threadCount>5</threadCount>
        -->
    
        <properties>
           <property>   
                <name>parallel</name>     
                <value>methods</value>  
            </property>
            <property>   
                <name>threadcount</name>
                <value>5</value>        
            </property>
            <property>
                <name>dataproviderthreadcount</name>   
                <value>3</value>
            </property>
        </properties>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 2015-05-30
      • 2015-05-05
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多