In TestNG, you can set priorities for test methods to control the order in which they are executed. Priorities are used to define the sequence in which test methods should run within a test class. TestNG executes methods with lower priority values before those with higher priority values.
Here’s an example of how to use priorities in TestNG:
javaCopy codeimport org.testng.annotations.Test;
public class ExampleTest {
@Test(priority = 1)
public void testMethod1() {
System.out.println("This is test method 1");
}
@Test(priority = 2)
public void testMethod2() {
System.out.println("This is test method 2");
}
@Test(priority = 0)
public void testMethod3() {
System.out.println("This is test method 3");
}
}
In this example, testMethod3 has the highest priority (0), so it will be executed first. Then, testMethod1 with priority 1 will be executed, followed by testMethod2 with priority 2.
You can use priorities to define the order of execution for your test methods to ensure that certain tests run before others, especially when there are dependencies between them.