【问题标题】:how to execute testng tests in parallel using maven surefire plugin如何使用 Maven Surefire 插件并行执行 testng 测试
【发布时间】:2018-11-21 20:15:32
【问题描述】:

我正在尝试使用 maven surefire 插件并行执行 Testng 测试。

请在下面找到我正在使用的配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
    <skipTests>${skipTests}</skipTests>
    <suiteXmlFiles>
        <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
    </suiteXmlFiles>
    <parallel>tests</parallel>
    <threadCount>5</threadCount>
    <systemProperties>
        <property>
            <name>testData</name>
            <value>${testData}</value>
        </property>
        <property>
            <name>testDataDelimiter</name>
            <value>${testDataDelimiter}</value>
        </property>
    </systemProperties>
    </configuration>
</plugin>

使用此配置,我只能看到一个线程开始执行。有人可以建议我并行执行 testng 测试的解决方案吗?

【问题讨论】:

  • parallel 没有 tests 值...你试过 methodssuites 吗?
  • 是的,我尝试了方法,但也没有用。此外,使用方法我只能看到一个线程被触发。

标签: java maven testng maven-surefire-plugin


【解决方案1】:

最明显的一种是使用parallel 参数。可能的值取决于使用的测试提供程序。对于 JUnit 4.7 及更高版本,这可能是方法、类、both、套件、suitesAndClasses、suitesAndMethods、classesAndMethods 或全部。作为 JUnit 测试的先决条件,JUnit runner 应该扩展 org.junit.runners.ParentRunner。如果没有通过注解@org.junit.runner.RunWith 指定运行器,则满足前提条件。

自 maven-surefire-plugin:2.1.6 以来,both 值已被弃用。

使用以下参数配置并行度的扩展。参数 useUnlimitedThreads 允许无限数量的线程。除非 useUnlimitedThreads=true,否则参数 threadCount 可以与可选参数 perCoreThreadCount=true(默认为 true)一起使用。参数 useUnlimitedThreads 和 threadCount 将在为并行参数指定的值的上下文中解释。

我建议将 useUnlimitedThreads 设置为 false,而是尝试使用 threadCount。从 10 之类的东西开始,然后逐步增加,直到找到一个不会对 CPU 造成太大压力的可接受线程数。

我直接从 TestNG Surefire 文档中获取了这个作为起点:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M1</version>
        <configuration>
          <properties>
            <property>
              <name>parallel</name>
              <value>methods</value>
            </property>
            <property>
              <name>dataproviderthreadcount</name>
              <value>30</value>
            </property>
          </properties>
        </configuration>
</plugin>

请注意,您需要将dataproviderthreadcount 属性和parallel 属性设置为methods 才能并行执行测试方法。

【讨论】:

  • 我正在使用参数 tests5 。你是不是想说 tests 不正确。我什至尝试过 methods 但它没有奏效。我只能看到一个线程被触发。
  • 如果您使用的是 JUnit,哪个版本?
  • 我正在使用TestNG -6.9.8
  • 您将需要使用dataproviderthreadcount。查看修改后的答案。
猜你喜欢
  • 1970-01-01
  • 2013-07-22
  • 2021-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多