运行 并行跨不同测试的 testng 方法

Run testng methods across different tests in parallel

我的 testng.xml 文件中有多个测试标签,我 运行 使用 maven。我已将套件级别的并行属性设置为方法,并将线程数设置为 5。我面临的问题是测试是按顺序执行的,只有测试用例中的方法是并行执行的。更清楚地说,虽然有未使用的线程(在我的例子中是网格中的 Selenium 节点)可用,但后续测试会等到执行前一个测试中的所有方法。

这是我用过的testng.xml,

<suite name="Suite1" verbose="1" parallel="methods" thread-count="5" preserve-order="false">
  <test name="Login" >
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>
  </test>

  <test name="Product Search">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>
  </test>
</suite>

由于我的 selenium 网格中有超过 10 个可用节点,此行为会显着增加执行时间并破坏具有网格体系结构的目的。如果有一种方法可以让我在整个套件中并行执行测试方法,请告诉我。我确定我遗漏了一些愚蠢的东西,但你能帮我指出吗?

在您的 TestNG xml 文件中输入 parallel="tests"

Parallel=methods 可以做到这一点 - "methods inside the test cases are executed in parallel"。

如果您希望并行执行测试标签,请使用 parallel=tests。
这将 运行 您所有的测试标签并行。

但是你说你有 10 个节点可用。如果以上是您仅有的 xml,那么一次只会用完两个节点,因为您只有两个测试标签。

<suite name="Suite1" verbose="1" parallel="tests" thread-count="2" preserve-order="false">   
  <test name="Login" parallel="methods" thread-count="5">
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>   
  </test>
  <test name="Product Search" parallel="methods" thread-count="5">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>   
  </test> 

首先允许您的套件 运行 "tests" 与测试套件的数量并行 运行 一次(示例 2)。

其次让你的测试运行"methods"与每个方法的数量运行并行(每个示例5)。

如果您遇到线程限制,请在调整这些数字时小心。例如,如果您添加另一个 thread-count 为 5 的测试组并将您的套件 thread-count 更改为 3。您现在将处于 15 个线程。