前面简要讲了关于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 | |||||
x | y | plus() | times() | divide() | floating() |
2 | 3 | 5 | 6 | 0 | 0.6666667 |
0 | 0 | 0 | 0 | error | error |
0 | 0 | 0 | 0 | ||
200 | 300 | 500 | 60000 | 0 | 0.6666667 |
2 | 3 | 10 | 10 | 10 | |
200 | 3 | 5 | 6 | 0 | 0.6666667 |
2 | -3 | -1 | -6 | -0 | -0.6666667 |
然后写出加载FIT框架的代码:
1
// Copyright (c) 2002 Cunningham & Cunningham, Inc.
2
// Released under the terms of the GNU General Public License version 2 or later.
3
4
using System;
5
using fit;
6
7
namespace eg
8
{
9
public class ArithmeticColumnFixture : ColumnFixture
10
{
11
12
public int x;
13
public int y;
14
15
public int plus()
16
{
17
return x + y;
18
}
19
20
public int minus()
21
{
22
return x - y;
23
}
24
25
public int times ()
26
{
27
return x * y;
28
}
29
30
public int divide ()
31
{
32
return x / y;
33
}
34
35
public float floating ()
36
{
37
return (float)x / (float)y;
38
}
39
40
public ScientificDouble sin () {
41
return new ScientificDouble(Math.Sin(toRadians(x)));
42
}
43
44
public ScientificDouble cos () {
45
return new ScientificDouble(Math.Cos(toRadians(x)));
46
}
47
48
private double toRadians(double degrees) {
49
return (degrees * Math.PI) / 180d;
50
}
51
}
52
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
51
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
52
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
下面解释一下:
注意到表的第一行:
eg.ArithmeticColumnFixture
什么意思?看看源代码,你发现了什么呢?,没错,表的第一行就是源代码所描述的类的名称.你可能已经想到这个类的方法和表的关系了.
很明显,表的x,y分别对应代码12行的public int x;13行的public int y;(这里x,y必须为public).
后面的plus(),times(),divide(),floating()那就分别对应类的其他方法了.
所以,我们可以想象得到FIT框架其实就是读取以表格形式描述的客户测试案例的数据到测试类里面去,然后配上NUnit的协作,最终完成了自动化测试.