日期:2014-05-20 浏览次数:21269 次
package com.walkman.junit.test; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import com.walkman.junit.Demo; import junit.framework.TestCase; import static org.junit.Assert.*; import static org.hamcrest.Matchers.*; public class DemoTest extends TestCase { @BeforeClass public static void beforeClass() { System.out.println("beforeClass"); } @AfterClass public static void afterClass() { System.out.println("afterClass"); } @Before public void before() { System.out.println("before"); } @Test public void testAdd() { int z = new Demo().add(3, 5); // assertEquals(8, z); // fail("Not yet implemented"); assertThat(z, is(8)); } @Test public void testDivide(){ double z = new Demo().divide(18, 6); assertThat(z, is(3.0)); } @Ignore @Test(expected=java.lang.ArithmeticException.class) public void testDivideTwo() { double z = new Demo().divide(8, 0); } }