ITeye博客

junit

共 3 篇文章

用JUNIT测试堆栈的例子

package com.test.junit; public class MyStack { private String[] elements; private int nextIndex; public MyStack() { elements = new String[100]; nextIndex = 0; } public void push(String element) throws Exception { if (100 == nextIndex) { throw new Exception("数组越界异常!"); } elements[nextIndex++] = elem…

2010-11-09 23:02 · junit · junit

用Junit测试数据库

package com.test.db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import org.junit.BeforeClass; import org.junit.Test; import com.test.bean.Person; public class Perso…

2010-11-09 22:59 · junit · junit · SQL · Bean

初学junit笔记一

在junit3.8中,测试方法满足如下原则: 1)public的 2)void的 3)无方法参数 4)方法名称必须以test开头 5)继承自TestCase 出名的语句:keep the bar green to keep the code clean 测试一个方法会在某种情况下抛出异常的方法: public void testDivide2() { Throwable tx = null; try { Calculator cal = new Calculator(); cal.divide(3,0); Assert.fail(); //Junit程序执行到这个语句时会直接终止testCa…

2010-10-10 23:20 · junit · junit · Eclipse · Ant · Swing