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. #qababu.com #HappyLearning #HappyTesting

2 comments:

  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

    ReplyDelete
  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

    ReplyDelete

Java Program 6: How to reverse a String in Java?

In this post we will discuss different methods to reverse a String in java programming. Method 1: Step 1: Read the input string using ...