package testjavapro; import org.junit.*; import org.junit.Test; import static org.junit.Assert.assertEquals; public class testjava { @BeforeClass public static void beforeClass() { System.out.println("@BeforeClass"); } @Before public void before() { System.out.println("@Before"); } @Test(timeout = 50) public void testTimeout() { System.out.println("@Test(timeout = 50)"); } @Test(expected = ArithmeticException.class) public void testExcepted(){ System.out.println("@Test(expected = Exception.class)"); throw new ArithmeticException(); } @Test public void test(){ System.out.println("@Test"); assertEquals(5 + 5, 10); // 判断是 5+5 是否等于 10 } @After public void after() { System.out.println("@After___________"); } @AfterClass public static void afterClass() { System.out.println("@AfterClass"); } } 输出 @BeforeClass @Before @Test(timeout = 50) @After___________ @Before @Test(expected = Exception.class) @After___________ @Before @Test @After___________ @AfterClass