如何在 maven 和 Testng 中 运行 并行套件

How to run parallel suites in maven and Testng

我想从 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 文件,它们是测试套件。 请让我知道如何 运行 并行套件。

TestNG 不支持并行模式 "suites",无论是通过 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 <test> nodes and define the parallelism in the testng.xmltests.

你可以试试 <threadCountSuites>8</threadCountSuites> 属性 并且不要设置线程数 属性 或将其设置为 0。