Hello Folks,

We learn about priority of test methods in a TestNG class in this post.
TestNG Tutorials 22: @Test Annotation – Games Of Priority Of Methods In TestNG

Do you know that TestNG will execute methods in unexpected order if you provide duplicate priorities and can create a nightmare for you. We will see some examples below:
Create a testng class with some test methods and provide them sequential priority starting from 1. Create another testng class with some test methods and provide them sequential priority starting from 1. Include both classes in testng.xml and run. You would expect first test methods of class 1 will run followed by methods of class 2. Let’s see here:
Class Research1:

Class Research2:




You can notice TestNG didn’t run test methods class by class. It grouped test methods based on similar priority and executed one after one. It may be problem for us if first method (testB1) of second class is dependent on 3rd methods(testA3) of first class but here testB1 executed by testA3. To handle these cases, you must need to pass priorities in sequence.


Change priority of methods testB1, testB2, testB3 in second class “Research2” as 4, 5 and 6 respectively and run testng.xml.


Now TestNG runs methods class after class. Similar types of situation can occur in other scenarios also. So always try to provide priority in sequential order not duplicate.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

6 thoughts on “TestNG Tutorials 23: @Test Annotation – Don’t Confuse TestNG With Duplicate Priorities

  1. testA1 from Research1 class and value is : 10
    testA2 from Research1 class and value is : 11
    testA3 from Research1 class and value is : 12
    testB! from Research1 class and value is : 10
    testB2 from Research1 class and value is : 11
    testB3 from Research1 class and value is : 12

    How to get this output with having priority in both classes as 1,2,3 ?

  2. Hello,
    I have 2 classes with each class containing 10 test methods prioritized from 1 to 10. Now when i place these in testng.xml only priority 1 tests from each of the classes are executed and then script exits.

    Note: for each test method I am opening browser, performing action and then closing the browser.

    If I remove the priorities or provide the priorities in sequence then it works fine. Please help me with this, it’s bothering me a lot.

  3. Good One Amod… Just a question, if i have 100 class with each having 3 test methods, then should i give my priority as running number starting from 1 for 1st @test method in class 1 to 300 for 3rd @test method in 300 class.. is there any alternative for this to make testng read class wise..


Leave a Reply