I am using JUnit and Selenium Webdriver. I want to run my test methods in order as how I write them in my code, as below:
@Test
public void registerUserTest(
You can sort methods with @FixMethodOrder(MethodSorters.NAME_ASCENDING)
annotation. Like,
@FixMethodOrder(MethodSorters.DEFAULT)
public class DefaultOrderOfExecutionTest { private static StringBuilder output = new StringBuilder("");
@Test
public void secondTest() {
output.append("b");
}
@Test
public void thirdTest() {
output.append("c");
}
@Test
public void firstTest() {
output.append("a");
}
@AfterClass
public static void assertOutput() {
assertEquals(output.toString(), "cab");
}
}
You can perform sorting in 3 ways:
For more details please refer:The Order of Tests in JUnit