» 您尚未 登录   注册 | 社区服务 | FTP中心 | 帮助 | 社区 | 无图版 | 测试百科  | 测试Blog 
软件测试基地论坛 -> 新手园地 -> [FAQ]JUnit测试前置行为
 XML   RSS 2.0   WAP 

--> 本页主题: [FAQ]JUnit测试前置行为 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题
Fastpoint


该用户目前不在线
级别: 总版主
精华: 44
发帖: 5033
基地声望: 390 点
基地币: 1683 Bug
基地贡献: 0 点
好评度: 15 点
在线时间:818(小时)
注册时间:2005-10-08
最后登录:2008-07-22
查看作者资料 发送短消息 推荐此帖 引用回复这个帖子

[FAQ]JUnit测试前置行为

引用Kent Beck, Erich Gamma,连接地址:http://junit.sourceforge.net/doc/cookbook/cookbook.htm

What if you have two or more tests that operate on the same or similar sets of objects?

Tests need to run against the background of a known set of objects. This set of objects is called a test fixture. When you are writing tests you will often find that you spend more time writing the code to set up the fixture than you do in actually testing values.

To some extent, you can make writing the fixture code easier by paying careful attention to the constructors you write. However, a much bigger savings comes from sharing fixture code. Often, you will be able to use the same fixture for several different tests. Each case will send slightly different messages or parameters to the fixture and will check for different results.

When you have a common fixture, here is what you do:

1.Create a subclass of TestCase
2.Create a constructor which accepts a String as a parameter and passes it to the superclass.
3.Add an instance variable for each part of the fixture
4.Override setUp() to initialize the variables
5.Override tearDown() to release any permanent resources you allocated in setUp


For example, to write several test cases that want to work with different combinations of 12 Swiss Francs, 14 Swiss Francs, and 28 US Dollars, first create a fixture:

public class MoneyTest extends TestCase {
  private Money f12CHF;
  private Money f14CHF;
  private Money f28USD;
 
  protected void setUp() {
    f12CHF= new Money(12, "CHF");
    f14CHF= new Money(14, "CHF");
    f28USD= new Money(28, "USD");
  }
}


Once you have the Fixture in place, you can write as many Test Cases as you'd like.


[ 此贴被Fastpoint在2005-10-17 11:00重新编辑 ]


可不可不要这么样徘徊在目光内
你会察觉到我根本寂寞难耐
即使千多百个深夜曾在梦境内
我有吻过你这毕竟并没存在

人声车声开始消和逝
无声挣扎有个情感奴隶
是我多么的想她
但我偏偏只得无尽叹谓

其实每次见你我也着迷
无奈你我各有角色范围
就算在寂寞梦内超出好友关系
唯在暗里爱你暗里着迷
无谓要你惹上各种问题
共我道别吧别让空虚使我越轨
[楼 主] | Posted: 2005-10-14 19:18 顶端

软件测试基地论坛 -> 新手园地




软件测试基地上海测仕信息技术有限公司旗下网站
Copyright © 2005-2007 Cntesting.com, All Rights Reserved
沪ICP备06057721号

Powered by PHPWind Code © 2003-06 PHPWind
Total 0.151357(s) query 4, Time now is:11-23 07:33, Gzip disabled
You can contact us


每日一句:Loading...