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