2

We have a group of tests that can be run in parallel and a group of tests that can only be run sequentially.

I would like TestNG to execute all of them in one run but schedule sequential tests sequentially, and parallel tests in parallel. How I can achieve that with TestNG?

I considered the following:

  1. Define two test groups with @Test(group='parallel-tests') and @Test(group='sequential-tests') annotations and run each group separately with proper configuration. I don't like it because I wanted to execute both groups in one run.

  2. Create testng.xml file with two suites:

    <suite name="Suite1" verbose="1" >    
      <test name="ParallelGroup" parallel="classes" >
        <classes>
            <class name="testngtests.TestParallel"/>
        </classes>
      </test>    
      <test name="Sequential" parallel="false"  >
        <classes>
            <class name="testngtests.copy.TestSeq"></class>
        </classes>
      </test>
    </suite>
    

but then I will need to explcitly list classes or packages of tests to include.

A solution would be to combine both approaches, i.e., something like

<suite name="Suite1" verbose="1" >
  <test name="ParallelGroup" parallel="classes" >
    <test-group ref="parallel-tests" />
  </test>

  <test name="Sequential" parallel="false"  >
    <test-group ref="sequential-tests" />
  </test>
</suite>

but I see no way to reference to test groups in testng.xml, there's nothing like test-group ref in TestNG.

2

TestNG has many combinations for classes, packages, methods... For the groups you can use:

<test name="Test Suite">
        <groups>
            <run>
                <include name="Test Group1"/>
                <include name="Test Group2"/>
            </run>
        </groups>
</test>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.