自己的第二个junit的例子
package com.xinnuo.daos;/** * @author bimingwei * @描述:一个整数除法和乘法的工具类 */ public class Math { public static int divide(int x,int y) { try{ return x/y; } catch (Exception e) {// TODO: handle exceptionSystem.out.println("出错"); } return x/y; } public static int multiple(int x,int y) { return x*y; } } package com.xinnuo.daos;import org.junit.After;import org.junit.Ignore;import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import static org.junit.Assert.*;import org.junit.Test;public class MathTest {@BeforeClasspublic static void setUpBeforeClass() throws Exception {}@AfterClasspublic static void tearDownAfterClass() throws Exception {}@Beforepublic void setUp() throws Exception {}@Afterpublic void tearDown() throws Exception {}@Test//在这个位置加上(expected=ArithmeticException.class)的话,会一直显示test成功public void testDivide() { assertEquals(3,Math.divide(9,3)); assertEquals(3,Math.divide(10,3)); Math.divide(10,0); //除数不能为0,会抛出异常 } @Ignore("忽略乘法测试") @Test public void testMultiple() { fail("Not yet implemented"); } }