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