TestNG parallel execution

2019-02-15 09:02发布

问题:

I have 4 @Test methods and want to run each of them 3 times. I want to execute this all simultaneously, in 12 threads.

I created a testng.xml file like this

<suite name="Suite1" verbose="1" parallel="methods" thread-count="100">

  <test name="Test1">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

  <test name="Test2">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

  <test name="Test3">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

</suite>

If I set parallel="methods" TestNG executes 4 test methods in 4 threads for Test1, after that does the same for Test2, and then for Test3. But I do not want to wait for Test1 completion before running Test2. TestNG is able to run Test1, Test2 & Test3 simultaneously (if parallel="tests") but in this case it executes 4 test methods in sequence for each Test.

Is there a way to tell TestNG to not wait at all and start all methods for all Tests in separate threads?

回答1:

Have the suite run parallel tests and then each test can run parallel methods. Something like:

<suite name="Suite1" verbose="1" parallel="tests" thread-count="10">

  <test name="Test1" parallel="methods" thread-count="4">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

  <test name="Test2" parallel="methods" thread-count="4">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

  <test name="Test3" parallel="methods" thread-count="4">
    <classes>
      <class name="Tests"/>
    </classes>
  </test>

</suite>


回答2:

If these are the same tests, then you can use invocationCount and threadpoolsize. In your @Test annotation add invocationCount=3 and threadPoolsize as 3. In testng.xml, create just one test (instead of 3), set parallel=methods and thread-count=4.

Hope it helps.



回答3:

Try using this:

<suite name="suite"  parallel="methods"  thread-count="20">

Hope this helps.



标签: testng