Running tests in parallel in testng

By default, all tests are run sequentially in TestNG. But we can also execute tests in Parallel. In TestNG suite XML file, we can specify how you want to execute tests in parallel way. We can execute tests in parallel in below ways.
  • tests – Tests configured inside test tags are run in parallel.
  • classes – Tests from multiple classes are executed in parallel.
  • methods – Methods are executed in parallel.
  • instances – Test methods of Class Instances are executed in parallel.
Here is the syntax in XML suite file. Note that parallel attribute’s value is tests. It means that Tests configured inside test tags would be run in parallel.
 
<suite thread-count="3" name="mytestSuite" parallel="tests">

In below example, parallel attribute’s value is classes. It means that tests from org.softpost.Class1 and org.softpost.Class2 would be executed in parallel.
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite" parallel="classes" thread-count="2">
    <test name="Tests">
        <classes>
            <class name="org.softpost.Class1" />
            <class name="org.softpost.Class2" />
        </classes>
    </test>
</suite>                    

Web development and Automation testing

solutions delivered!!