Sunday, August 27, 2017

How to prioritize test cases from different test sets (java classes) in TestNG?

In the previous post we have seen the importance of priority and how to use it in TestNG in one test set, here a test set is nothing but a java class that contains one or more test cases (@test methods). Now we will learn prioritizing the test cases that are present in different test sets.
As show in the below screenshot we have one regression test and one smoke test. And each test contains two test sets.
Each test set is containing 3 test cases, and also each test cases is assigned with priority, please check the below screenshot.

Now create a testng.xml adding all the test sets under one test as shown below.

Run the testng.xml as TestNG suite and observe the order in which the test cases being executed.

All the first priority test cases across the test sets are executed, and second priority test cases next, and then third priority test cases. But this is not actually our requirement, this will lead to tests failure if the test cases are dependent on each other in a class. 
So our requirement is to execute all the test cases in a test set (regressionSet1) priority wise and then go to next test set(regressionSet2), execute all the test cases in priority-wise and so on. For this we need to modify the testng.xml file. We need to map each test set (java class) as one test in testng.xml as in the below screenshot.

This what we are expecting, observe the results now, all the test cases in regressionSet1 are executed first, priority-wise and then regressionSet2 test cases and so on.

This how we can prioritize and execute the test cases across different classes.

No comments:

Post a Comment

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 ...