发布时间: 2012-06-24 19:01:53 作者: rapoo
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);}}执行的结果如下图:
JAVA基础-java中ET的差异
ByteBuffer跟String的互相转换
vim 编辑器的三种模式怎么切换
电脑编码
地图reduce编程模型介绍
Java基础java缓存读写资料小例子
学习jar下令 创建和解压jar文件包
java生成随机数、四舍五入、当前时间的
[猖獗Java讲义精粹] 第十一章|多线程
Java Thread 小结