JUnit Annotation——JUnit单元测试中批注@详解[转]
import static org.junit.Assert.*; import org.junit.After;import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Ignore;import org.junit.Test; public class JUnit4Test {@Beforepublic void before() { System.out.println("@Before");}@Testpublic void test() { System.out.println("@Test"); assertEquals(5 + 5, 10);}@Ignore@Testpublic void testIgnore() { System.out.println("@Ignore");}@Test(timeout = 50)public void testTimeout() { System.out.println("@Test(timeout = 50)"); assertEquals(5 + 5, 10);}@Test(expected = ArithmeticException.class)public void testExpected() { System.out.println("@Test(expected = Exception.class)"); throw new ArithmeticException();}@Afterpublic void after() { System.out.println("@After"); } @BeforeClass public static void beforeClass() { System.out.println("@BeforeClass"); }; @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