junit4中annotation的几种应用package com.fsti.math;public class MathDemo {public int add(int a, int b) {return a + b;}public int div(int a, int b) {if (b == 0) {throw new ArithmeticException("除数不能为0!");}return a / b;}}package com.fsti.math;import static org.junit.Assert.*;import org.junit.*;public class MathDemoTest {MathDemo md = null;@BeforeClasspublic static void setUpBeforeClass() throws Exception {System.out.println("setUpBeforeClass......");}@AfterClasspublic static void tearDownAfterClass() throws Exception {System.out.println("tearDownAfterClass......");}@Beforepublic void setUp() throws Exception {System.out.println("SetUp...");md = new MathDemo();}@Afterpublic void tearDown() throws Exception {System.out.println("TearDown...");md = null;}@Testpublic void testAdd() {int expected = 3;int actual = md.add(1, 2);assertEquals(expected, actual);}@Testpublic void testDiv() {int expected = 3;int actual = md.div(6, 2);assertEquals(expected, actual);}@Test(expected=ArithmeticException.class)public void testDivWithZero() {int expected = 3;int actual = md.div(6, 0);assertEquals(expected, actual);}@Test(timeout=100)public void testDivWithTimeout() {int expected = 3;int actual = md.div(6, 2);assertEquals(expected, actual);}@Test@Ignorepublic void testIgnore() {assertEquals(1, 1);}}执行的结果如下图: