【问题标题】:How to run parallel suites in maven and Testng如何在 Maven 和 Testng 中运行并行套件
【发布时间】:2017-08-01 01:16:51
【问题描述】:

我想平行于 maven 的测试套件。 我的 pom.xml 如下所示:

<profiles>
        <profile>
            <id>API_AUTOMATION</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <parallel>suites</parallel>
                            <threadCount>8</threadCount>
                            <suiteXmlFiles>
                                <!-- TestNG suite XML files -->
                                <suiteXmlFile>./module1.xml</suiteXmlFile>                              
                             <suiteXmlFile>./module2.xml</suiteXmlFile>
                            </suiteXmlFiles>
                            <testSourceDirectory>src/main/java</testSourceDirectory>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
</profiles>

所有.xml 文件都是TestNG 文件,它们是测试套件。 请告诉我,如何并行运行这些套件。

【问题讨论】:

  • 请通过编辑在您的问题中添加错误描述。虽然Surefire documentation 说它应该是&lt;file&gt; 而不是&lt;suiteXmlFile&gt; 它在我的测试中有效(可能是一个错误,一开始它也说&lt;suiteXmlFile&gt;)。其余的看起来也不错。
  • 我使用以下命令 mvn clean test -Dmaven.test.failure.ignore=true -Djdk.level=1.7 -P API_AUTOMATION 运行了测试,但它没有并行运行测试,它按顺序运行。
  • 您可以尝试使用 8 属性,不要设置线程计数属性或将其设置为 0。
  • @Murthi,能否请您保留您的评论作为答案,我会接受 - 谢谢 Sarada

标签: maven testng maven-surefire-plugin


【解决方案1】:

你可以试试 &lt;threadCountSuites&gt;8&lt;/threadCountSuites&gt; 属性,不要设置线程计数属性或设置为0。

【讨论】:

    【解决方案2】:

    TestNG 不支持并行模式“套件”,无论是通过 Surefire 还是通过任何运行类型的 TestNG。

    来自文档中的command line options

    -parallel    methods|tests|classes    If specified, sets the default 
                                          mechanism used to determine how 
                                          to use parallel threads when 
                                          running tests. If not set, 
                                          default mechanism is not to use 
                                          parallel threads at all. This can 
                                          be overridden in the suite 
                                          definition.
    

    证明可以在v6.11 sources of XmlSuite:

    public class XmlSuite implements Serializable, Cloneable {
      /** Parallel modes */
      public enum ParallelMode {
        TESTS("tests", false), METHODS("methods"), CLASSES("classes"), INSTANCES("instances"), NONE("none", false),
    
        ...
      }
      ...
    }
    

    这适用于 TestNG 6.11 及更早的版本。

    考虑将多个 .xml 文件中的测试添加到一个 .xml 文件中,multiple &lt;test&gt; nodesdefine the parallelism in the testng.xmltests

    【讨论】:

      猜你喜欢
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 2016-09-17
      • 2019-01-08
      • 1970-01-01
      • 2012-05-10
      相关资源
      最近更新 更多