TestNG enables you to run test methods, test classes and test cases in parallel inside your project. By performing parallel execution, we can reduce the 'execution time' as tests are started and executed simultaneously in different threads.

Here we will see how to run multiple classes (aka different suites) using TestNG.

Creating a TestNG.xml file for executing test

In order to do that follow the below steps.

  1. Create a new project in eclipse
  2. Create two packages in the projects (name them as com.suite1 and com.suite2)
  3. Create a class in each package (name them as Flipkart.java and Snapdeal.java) and copy the below code in respective classes
  4. Create a new file in your project and name it as testing.xml (Make sure you've installed testing plugin for eclipse, instructions available here). Testng.xml contains all configuration (classnames, testnames and suitnames.

Final project structure looks like below,

TestNG: Execute multiple Test Suites

Parallel execution in TestNG

After creating xml file as shown above, in next step, we will execute the parallel test. Below is the code.

TestNG: Execute multiple Test Suites

1) thread-count: This is used for parallel execution, based on the number script. It will execute in parallel or sequential order.

2) verbose: It is used to log the execution details in the console. The value should be 1-10. The log details in the console window will get more detailed and clearer as you increase the value of the verbose attribute in the testng.xml configuration file.

3) name: Name of the suite. Here it is "Gmail Suite"

4) Parallel: To run scripts parallel, value can be tests/classes/methods/suites. Default value is none

Right click on the testing.xml and select run as testing, once successful you'll see all the results

When you execute the above code, you will get the following output.


TestNG: Execute multiple Test Suites

1 name of the suite given in testng.xml

TestNG: Execute multiple Test Suites

2 name of the test given in testng.xml

TestNG: Execute multiple Test Suites

3 name of the class given in testng.xml

TestNG: Execute multiple Test Suites

4 method names annotated with @Test in .java file

TestNG: Execute multiple Test Suites

Likewise, it will execute test suite for snap deal as well.


Here we have seen how to use testng to execute parallel test. TestNG gives an option to execute multiple test in parallel in a single configuration file (XML).