JUnit – 特定の順序でテストを実行する
JUnitでは `@FixMethodOrder(MethodSorters.NAME__ASCENDING)`を使ってメソッド名でテストメソッドを辞書順に実行できます。
P.S JUnit 4.12
でテスト済み
ExecutionOrderTest.java
package com.mkyong;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
//Sorts by method name
@FixMethodOrder(MethodSorters.NAME__ASCENDING)
public class ExecutionOrderTest {
@Test
public void testB() {
assertThat(1 + 1, is(2));
}
@Test
public void test1() {
assertThat(1 + 1, is(2));
}
@Test
public void testA() {
assertThat(1 + 1, is(2));
}
@Test
public void test2() {
assertThat(1 + 1, is(2));
}
@Test
public void testC() {
assertThat(1 + 1, is(2));
}
}
上記のテスト方法は、次の順序で実行されます。
test1 test2 testA testB testC

テストの実行順序が本当に必要な場合は、
TestNG Dependency Test
参考文献
MethodSorters JavaDoc]。
https://github.com/junit-team/junit4/wiki/Test-execution-order
[JUnit
テスト実行の順序]