When the @Test annotation in TestNG does not have a priority attribute, the test method is assigned a default priority of 0. If multiple test methods are defined with explicit priorities such as 1, 2, or 3, the test without a priority (i.e., with default priority 0) will be executed before those.
To execute any test before the one with default priority 0, you need to assign it a negative priority value (e.g., -1, -2, etc.).
Example:
@Test
public void test1() {
System.out.println("Test 1");
}
@Test(priority = 1)
public void test2() {
System.out.println("Test 2");
}
@Test(priority = -1)
public void test3() {
System.out.println("Test 3");
}
Output:
Test 3 // priority -1
Test 1 // priority 0 (default)
Test 2 // priority 1