FIT FOR .NET(3)

文章将详细介绍FIT的用法,可访问http://fit.c2.com获取最新信息。先介绍ColumnFixture,通过算术例子解释,表第一行对应源代码类名,表中x、y等对应类的变量和方法。FIT框架读取表格测试案例数据到测试类,配合NUnit完成自动化测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前面简要讲了关于FIT的用法(参看FIT For .NET(0) ,FIT For .NET(1) FIT FOR .NET(2)),在接下来的文章中,我将详细介绍FIT的用法.由于FIT的不断更新,其文档也是不断进步,所以为了得到最近的信息,请访问http://fit.c2.com .

首先介绍ColumnFixture:

Coulmn映射测试数据的列到子类的方法或变量.

一个新的Column fixture为每个使用它的表创建,同样的Column fixture会从上到下处理每行,从左到右处理每列.CalculatorExample 这个例子就是这样.x()因数时第一个方法列,不管Key如何改变,都可以得到检查

你可以参看一下资源:

还是举个例子详细解释一下吧.
 拿个算术的例子.这个算术包括加减乘除.
 我们可以写测试案例为(以表的形式):

eg.ArithmeticColumnFixture
xyplus()times()divide()floating()
235600.6666667
0000errorerror
0000
2003005006000000.6666667
23101010
20035600.6666667
2-3-1-6-0-0.6666667

然后写出加载FIT框架的代码:
 1 None.gif //  Copyright (c) 2002 Cunningham & Cunningham, Inc.
 2 None.gif //  Released under the terms of the GNU General Public License version 2 or later.
 3 None.gif
 4 None.gif using  System;
 5 None.gif using  fit;
 6 None.gif
 7 None.gif namespace  eg
 8 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 9InBlock.gif    public class ArithmeticColumnFixture : ColumnFixture 
10ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
11InBlock.gif
12InBlock.gif        public int x;
13InBlock.gif        public int y;
14InBlock.gif
15InBlock.gif        public int plus() 
16ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
17InBlock.gif            return x + y;
18ExpandedSubBlockEnd.gif        }

19InBlock.gif
20InBlock.gif        public int minus() 
21ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
22InBlock.gif            return x - y;
23ExpandedSubBlockEnd.gif        }

24InBlock.gif
25InBlock.gif        public int times () 
26ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
27InBlock.gif            return x * y;
28ExpandedSubBlockEnd.gif        }

29InBlock.gif
30InBlock.gif        public int divide () 
31ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
32InBlock.gif            return x / y;
33ExpandedSubBlockEnd.gif        }

34InBlock.gif
35InBlock.gif        public float floating () 
36ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
37InBlock.gif            return (float)x / (float)y;
38ExpandedSubBlockEnd.gif        }

39InBlock.gif        
40ExpandedSubBlockStart.gifContractedSubBlock.gif        public ScientificDouble  sin () dot.gif{
41InBlock.gif            return new ScientificDouble(Math.Sin(toRadians(x)));
42ExpandedSubBlockEnd.gif        }

43InBlock.gif
44ExpandedSubBlockStart.gifContractedSubBlock.gif        public ScientificDouble  cos () dot.gif{
45InBlock.gif            return new ScientificDouble(Math.Cos(toRadians(x)));
46ExpandedSubBlockEnd.gif        }

47InBlock.gif
48ExpandedSubBlockStart.gifContractedSubBlock.gif        private double toRadians(double degrees) dot.gif{
49InBlock.gif            return (degrees * Math.PI) / 180d;
50ExpandedSubBlockEnd.gif        }

51ExpandedSubBlockEnd.gif    }

52ExpandedBlockEnd.gif}


下面解释一下:
注意到表的第一行:
eg.ArithmeticColumnFixture
什么意思?看看源代码,你发现了什么呢?,没错,表的第一行就是源代码所描述的类的名称.你可能已经想到这个类的方法和表的关系了.
很明显,表的x,y分别对应代码12行的public int x;13行的public int y;(这里x,y必须为public).
后面的plus(),times(),divide(),floating()那就分别对应类的其他方法了.

所以,我们可以想象得到FIT框架其实就是读取以表格形式描述的客户测试案例的数据到测试类里面去,然后配上NUnit的协作,最终完成了自动化测试.

转载于:https://www.cnblogs.com/confach/archive/2005/04/25/144836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值