« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
关注电子政务、大型企业应用开发、Web、Workflow、MOM、MDA、RCP、GEF email:gmluyang@gmail.com
|
Blog信息 |
blog名称:SixSun的Blog 日志总数:152 评论数量:372 留言数量:13 访问次数:2380428 建立时间:2004年12月13日 |

| |
[软件测试]利用JUNIT进行单元测试(下) 文章收藏, 网上资源, 软件技术
SixSun 发表于 2004/12/17 22:20:47 |
5. 编写测试代码
/*
* Created on 2004-2-9
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.yjsoft.test;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.yjsoft.app.HelloWorld;
/**
* @author yanghx2004
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class HelloWorldTest extends TestCase {
/**
* Constructor for HelloWorldTest.
* @param arg0
*/
public HelloWorldTest(String arg0) {
super(arg0);
}
public static void main(String[] args) {
junit.swingui.TestRunner.run(HelloWorldTest.class);
}
public void testSayHello() {
HelloWorld world=new HelloWorld();
//Assert.assertNull(world);
assertEquals(world.sayHello(),"Hello World");
}
public void testAdd() {
HelloWorld world=new HelloWorld();
//Assert.assertNull(world);
Assert.assertEquals(world.add(1,2),3);
}
}
6. 测试
500)this.width=500'>
发现失败,方法为sayHello(),看看具体信息“应为Hello word. 却发现 Hello World”
修改测试函数
assertEquals(world.sayHello(),"Hello world.");
7. 测试,通过
8. 500)this.width=500'>
关于JUNIT简单使用就介绍这么多, 关于用JUNIT来模拟请求进行JSP测试,我下次讲解。这要涉及到HttpUnit单元。 |
|
|