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:
Scenario: 
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:

TestNg.xml:

Output:

 

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.

Solution:

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

Output:

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.
#ThanksForReading
#HappySelenium

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

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

    Thanks!

Leave a Reply