Friday, August 25, 2017

How to execute multiple test cases in TestNG?

There are different ways to execute the multiple test cases in TestNG using testng.xml file. As discussed in my previous post Importance of testng.xml testng.xml is used to define the test execution process. We can definethe test execution process based on requirement in testng.xml files. And we can have more than one testng.xml file (with different title) in your project. In this post we will discuss about different ways to execute the multiple test cases.

Assume we have a TestNG project with regression tests (“regressionTests”) and smoke tests (“smokeTests”). And regressionTests contains two sets of test cases regressionSet1 and regressionSet2. Similarly smokeTests contains smokeSet1 and smokeSet2. Each test set contains three test cases (@test methods). Please find the screen shot below.

Method 1: Executing all the tests as one test

Create a testng.xml file as shown below. The .xml file should contain only one <test> tag and all the “classes” under different packages should be added under it. Here each java class is a test set that contains one or more test cases (@test methods) in it. Now run the testng.xml file as TestNG suite, all the test cases from each java class will be executed.

Check the results report below, you can see all the test sets being executed under one test.

Method 2: Executing Regression and Smoke tests as different tests

Create another testng2.xml, and add the test sets (“classes”) under different <test> tags in the .xml file as shown in the below screen shot.

Now run the testng2.xml as TestNG suite and check the results report below, you can see all the test sets being executed under two different tests.

Method 3: Executing each test set as one test

There are four test sets ('java classes') for each set we have to add one <test> tag in the .xml file as shown in the below screenshot. lets us name the file as testng3.xml

Run the testng3.xml file as TestNG suite, and check the results report, you should see four test sets being executed as four different tests.

These are some of the ways to execute the multiple test cases in TestNG. If you want to skip any test set from the execution just remove that <test>/<test> from the .xml file.

Thanks for reading. #HappyLearning #HappyTesting


  1. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.

    software testing course in chennai

  2. I enjoyed reading your post. I will share it with my other friends as the information is really very useful. Keep sharing your excellent work. Best Core Java With Data Structures Course In Delhi

  3. Nice Blog, When I was read this blog, I learnt new things & it’s truly have well stuff related to developing technology, Thank you for sharing this blog. Need to learn software testing companies, please share. It is very useful who is looking for
    Low code automation platform
    Mobile Testing Services
    QA Services


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...