reference:
http://dev.yesky.com/275/2132275.shtml
1.在eclipse新建一个java project
2.新建一个class: hello, package = example, 代码如下:
package example;
public class hello
{
public int abs(int n)
{
return n >= 0 ? n : (-n);
}
}
3.右键点击hello.java,选择:new - junit test case
setUp / tearDown打钩, 最下方click here点击,添加JUnit.jar文件 - next
4.选择abs()方法
5.修改Hellotest代码:
package example;
import junit.framework.TestCase;
public class helloTest extends TestCase
{
private hello _hello;
protected void setUp() throws Exception
{
super.setUp();
_hello = new hello();
}
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testAbs()
{
assertEquals(_hello.abs(14), 14);
assertEquals(_hello.abs(-5), 5);
assertEquals(_hello.abs(0), 0);
}
}
6. 运行
posted on 2008-12-03 15:38
张辰 阅读(132)
评论(0) 编辑 收藏