Assigning Priority to Test cases in TestNG

August 21, 2016

Default Priority of Test cases in TestNG:

In TestNG, by default execution of the test cases is in alphabetic order. Consider a below example which has 4 test cases which are defined in random order in Java Class.

Result of above Execution:

[TestNG] Running:
C:\Users\Saurabh\AppData\Local\Temp\testng-eclipse–1602420994\testng-customsuite.xml

Test case 1
Test case 2
Test case 3
Test case 4

Defining Priority of test cases:

An attribute called priority can be passed to change the priority of a test case.

Priority attribute takes integer value as an input, least the value of integer high is the priority.

Example:

Based on the priority set for the test cases in above code. Order of execution will be:

Test case 3
Test case 1
Test case 4
Test case 2

PS: For any questions queries or comment feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning 🙂

Saurabh

About the Author

Saurabh

Follow Saurabh:

Leave a Comment: