Prioritizing / Sequencing of Test Cases in TestNG

  • When you want to put a number of tests under a test class and want to run everyone in one shot, then such situations will happen.
  • With the help of TestNG ‘@Test‘ annotation, we can do many tests in a single Testing file.
  • The number of test in the same test class and all to run in one shot.
  • You can run one or more test cases in your TestNG.xml file.
  • If we do not give @Test priority then execute @Test in alphabetical order.




1. Without / Zero Priority:

  • By default, all the priorities for the tests will be zero (ie, if you do not set a preference, it will give priority as zero).
  • If you give priority to all test cases, then according to all the tests it will be executed in alphabetical order.


  • Create three methods (a,b,c).
  • Without giving priority to any method execute the script.

Example: Example Test case without / Zero priority.


Note: It has not been executed in the sequence mentioned in the class. By default, the methods annotated by @Test are executed alphabetically.

2. With Priority:

  • All test cases will be executed on a priority basis.



  • Create three methods (a,b,c).
  • Give priority to each method then execute the script.


Example: Execute Test case to Prioritizing / Sequencing of Test Cases in TestNG


Note: priority = 1 will execute the test first and priority = 2 will execute second and priority = 3 will execute the final. In this way, we can prioritize tests in TestNG to control the execution flow.

Share something valuable to others

Leave a Reply

Your email address will not be published. Required fields are marked *