If you have more than a single test in your Class then you might noticed on executing, the test in the class are not executed in the order they have be written.
As it is important during testing to validate few area before executing the other test, this might be a big problem if you don't control the execution order. With the help of Priority in this framework we can control the order of execution
Syntax
@Test(priority=value)
e.g, @Test(priority=1)
Code
import org.testng.annotations.Test;
public class Priority_class{
@Test(priority=1)
void Testone(){
System.out.println("This is Test 1");
}
@Test(priority=2)
void Testtwo(){
System.out.println("This is Test 2");
}
@Test(priority=3)
void Testthree(){
System.out.println("This is Test 3");
}
}
Explanation
When executing the test without the priority with the test annotation the result in order of the execution may vary each and every time. When we mention the priority then the test containing the least no as their priority will be executed first then the next.
There is no condition the these no has to be continuing sequence i.e, instead of 1, 2 and 3. We might also assign 25, 88, 95 for the above example.
Result
Without Priority
With Priority