Prioritze tests in testNG


In the usual sense, the order of execution of code in TestNG is followed by ASCII sequence which makes the order of execution in a haphazard manner. The output result that we would expect would usually not match the desired manner. In order to solve this issue, we Prioritize the test case. 


  • Reduces time taken for execution. 
  • Increases code readability 
  • Helps in controlling the flow of code. 
  • Reduces anomalies in code. 


  • Download Eclipse IDE 
  • Create a maven project in Eclipse 
  • Add various dependencies like selenium, TestNG, WebDriver Manager 
  • Download and install TestNG from the Eclipse marketplace 


In the first step, we would be creating a maven project inside Eclipse.  We would fill in basic details like name, group id, description, etc. 

New Maven project

In the Second step, we would be adding a package and then create an execution file. 

Java Package

After creating the package, we would be creating different classes each performing different sets of actions as shown below. 

File Structure: 

File Structure- prioritizing Tests in TestNG

Test Case:

In the given Test Case, our task is to perform a flight booking test. In this Test we need to perform the following actions: 

  1. Sign up 
  2. Login 
  3. Search for the flight 
  4. Book the flight 
  5. Save the ticket 
  6. Logout  

We notice how is the flow/Sequence of execution is from the above. When we code for the same and print the following as shown below: 

Code- prioritizing Tests in TestNG

To understand better and thus reduce complications we are just printing out the statements in the given order. But when we run the TestNG file because of ASCII order the sequence of flow changes as shown below.

Code- prioritizing Tests in TestNG

We notice that although our test is passing the order of execution is very random so, in order to avoid this type of situation, we take the help of ’priority sequencing’ as shown below.

Code- prioritizing Tests in TestNG


  • We can also use negative priorities like (Priority =-3); this will count in an algebraic sequence. 
  • If we pass the same priority for multiple test cases it would be following ASCII sequence. 


Output- prioritizing Tests in TestNG

We notice the Sequence of execution flow by setting the priorities of execution that have been changed to the way we had desired. 

Test Report: 

Test Report

Click here to read the next blog on TestNG.