在AllTests类中编写一个@BeforeClass方法,该方法将在启动套件时执行。
public class MyTests1 { @BeforeClass public static void beforeClass() { System.out.println("MyTests1.beforeClass"); } @Before public void before() { System.out.println("MyTests1.before"); } @AfterClass public static void afterClass() { System.out.println("MyTests1.AfterClass"); } @After public void after() { System.out.println("MyTests1.after"); } @Test public void test1() { System.out.println("MyTests1.test1"); } @Test public void test2() { System.out.println("MyTests1.test2"); }}public class MyTests2 { @BeforeClass public static void beforeClass() { System.out.println("MyTests2.beforeClass"); } @Before public void before() { System.out.println("MyTests2.before"); } @AfterClass public static void afterClass() { System.out.println("MyTests2.AfterClass"); } @After public void after() { System.out.println("MyTests2.after"); } @Test public void test1() { System.out.println("MyTests2.test1"); } @Test public void test2() { System.out.println("MyTests2.test2"); }}@RunWith(Suite.class)@Suite.SuiteClasses( { MyTests1.class, MyTests2.class })public class AllTests { @BeforeClass public static void beforeClass() { System.out.println("AllTests.beforeClass"); } @Before public void before() { System.out.println("AllTests.before"); } @AfterClass public static void afterClass() { System.out.println("AllTests.AfterClass"); } @After public void after() { System.out.println("AllTests.after"); } @Test public void test1() { System.out.println("AllTests.test1"); } @Test public void test2() { System.out.println("AllTests.test2"); }}
输出值
AllTests.beforeClassMyTests1.beforeClassMyTests1.beforeMyTests1.test1MyTests1.afterMyTests1.beforeMyTests1.test2MyTests1.afterMyTests1.AfterClassMyTests2.beforeClassMyTests2.beforeMyTests2.test1MyTests2.afterMyTests2.beforeMyTests2.test2MyTests2.afterMyTests2.AfterClassAllTests.AfterClass
hth
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)