これは私が持っているもので、うまく動作します。
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ TestSuite1.class, TestSuite2.class })
public class CompleteTestSuite {
@BeforeClass
public static void setUpClass() {
System.out.println("Master setup");
}
@AfterClass public static void tearDownClass() {
System.out.println("Master tearDown");
}
}
私のテストスイート1(テストスイート2も同じです)です。
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(value = Suite.class)
@SuiteClasses(value = { TestCase1.class })
public class TestSuite1 {}
これは私のテストクラスです。 testcase1とtestcase2の両方を作成します。
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestCase1 {
@BeforeClass
public static void setUpClass() {
System.out.println("TestCase1 setup");
}
@Test
public void test1() {
assertEquals(2 , 2);
}
}
あなたは5つのクラス completesuite suite1 suite2 test1の test2の
を持っている必要があり、あなたのビルド・パスにJUnitのを持っていることを確認してください。これは実行する必要があります!ここで
は、それが動作するはずこの回答によると、出力
Master setup
TestCase1 setup
Master tearDown
です:http://stackoverflow.com/questions/82949/before-and-after-suite-execution-hook-in-junit- 4-x#177069 – Sebi