You should never write tests that need to be executed in a specified order. That's really bad practice. Every test should be able to run independent.
but if you want it.
Junit 4.11 comes with @FixMethodOrder annotation. Instead of using custom solutions just upgrade your junit version and annotate test class with FixMethodOrder(MethodSorters.NAME_ASCENDING). Check the release notes for the details.
Here is a sample:
[code:1ho9wetd]import org.junit.runners.MethodSorters;
import org.junit.FixMethodOrder;
import org.junit.Test;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SampleTest {
@Test
public void firstTest() {
System.out.println("first");
}
@Test
public void secondTest() {
System.out.println("second");
}
}
[/code:1ho9wetd]