首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JUnit Annotation——JUnit单元测试中眉批@详解[转]

2013-11-20 
JUnit Annotation——JUnit单元测试中批注@详解[转]import static org.junit.Assert.* import org.junit.Af

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

热点排行