How to run test methods in specific order in JUnit4?

I want to execute test methods which are annotated by @Test in specific order.

For example:

public class MyTest {
    @Test public void test1(){}
    @Test public void test2(){}
}

I want to ensure to run test1() before test2() each time I run MyTest, but I couldn’t find annotation like @Test(order=xx).

I think it’s quite important feature for JUnit, if author of JUnit doesn’t want the order feature, why?

23 Answers
23

Leave a Comment