最近在工作中开始接触到一个新的开源测试框架Fitnesse,其主要用于Acceptence Testing。由于相关的中文资料真是少之又少,小弟就斗胆在此班门弄斧一下,供大家拍砖。
要谈Fitnesse,我们首先要先来了解一下FIT(Framework for Integrated Test),从字面翻译过来也就是集成测试框架。在软件开发过程中,沟通是一个非常重要的环节。往往由于一个需求的误解导致整体项目进度的滞后,而FIT的出现恰恰是很好解决了沟通这个问题。
FIT允许客户和测试人员通过表格的方式(如MicroSoft Excel),来告诉Programmer需求所希望的结果是什么。FIT通过相应的Fixture代码来自动确认需求是否被正确实现。
也就是说,我们把复杂的需求转化成为了一个又一个简单易懂的Table。
Fitnesse就是基于FIT的工作原理,但是Fitnesse它本身是一个Wiki,也就是说我们可以通过Wiki来管理我们的测试用例(也就是相应的Table),同时我们也可以在Wiki上来展现我们的测试结果,这样更加有助于我们进行测试用例的管理和Report的展现。
附件是Fitnesse的安装包
1.下载Fitnesse.zip安装包,
2.把Fitnesse.zip解压到本地
3.启动Run.bat文件,默认启动端口为80。若80端口已经被占用,可以通过记事本打开Run.bat文件,在后面加入“-p 端口号”,再保存运行即可。
3.打开浏览器,输入http://localhost:80,看到Fitensse首页面,就表示Fitnesse已经正确启动。
Fitnesee测试框架中有两个不同的测试方法,Slim和Fit。在工作中发现两者有不同的使用用途和方法。只有分析清楚了两者的区别和共同之处,才能选择出正确的测试方法来提高工作效率。
Fitnesse的默认测试方法是Fit,要使用Slim进行测试的话,需要在测试Page中指定
!define TEST_SYSTEM {slim} 我们可以把TEST_SYSTEM理解为系统变量。当然我们也可以用Define来定义一些用户自己的变量,这个就以后再写了。
Fit方法会从Fitnesse得到传来的Html文件,解析后和Fixture关联来执行Case,而Slim直接从Fitnesse中得到Html中的内容,因此Slim更加的轻便,有更好的独立性。
每一个测试类型都有自己对应的TestTable类型
Slim的TestTable如下
Decision Table | Supplies the inputs and outputs for decisions. This is similar to the Fit Column Fixture |
Query Table | Supplies the expected results of a query. This is similar to the Fit Row Fixture |
Ordered query Table | Supplies the expected results of a query. The rows are expected to be in order. This is similar to the Fit Row Fixture |
Script. Table | A series of actions and checks. Similar to Do Fixture. |
Table Table | Whatever you want it to be! |
Import | Add a path to the fixture search path. |
Comment | A table that does nothing. |
Scenario Table | A table that can be called from other tables. |
Fit的TestTable如下
ColumnFixture | This is the style. you may end up using most: rows of data represent inputs and expected outputs. |
RowFixture | This is good for testing queries that should return an exact set of values (order-independently). |
ActionFixture | This style. allows you write a script. that emulates a series of events (such as controls manipulated on a user interface). |
Comment Tables | Sometimes you want a tablular comment that is not executed as a test. |
Fit接受输入Null代表空指针,Blank代表空的字符串,而Slim不接受,因此对于Slim的输入,我们需要写一个Converter来进行转换。类似于
public String converter(String input)
if(input.equals("null")
return null;
else if (input.equals("blank"))
return "";
这样也就解决了转换的问题。
很晚了,睡觉去了,明天继续研究Fitnesse
浅谈Fitnesse测试框架 (三)
上次在第二季中介绍了Fitnesse中不同Table的类型。最近在工作中一直有遇到使用Action Fixture。在这里分享一下使用后的感受。今天先介绍一些Fit中的Action Fixture。
有一个需求大概就是说,addStudent(int i)这个函数会每次增加学生的数量,count()这个函数则是统计学生的数量。那么在测试过程中,我们需要先增加学生,再看看学生数量是不是已经正确增加。这个时候我们发现用ColumnFixture是很难完成的,这个时候我们就想到了选择Action Fixture。它可以让我们按照Case的流程来设计我们的自动化脚本。先来看看我写的ActionFixtureCode
Package QUERY; public class StudentFixture extends Fixture{ private int student; //initlize the student num to zero public void init(){ student =0; } //add the student num by i public void addStudent(int i){ student=student+i; } //return the student num public int count(){ return student; } } |
别忘记要引入fitnesse.jar,编译好生成的StudentFixture.class在D:\Eclipse_WorkSpace\Fitnesse\bin目录下面,接下去我们要去编写我们的Fitnesse的表格了。
启动Fitnese.bat,新建一个测试Page叫StudentTest
!path D:\Eclipse_WorkSpace\Fitnesse\bin !|Action Fixture| |start|QUERY.StudentFixture| |press|init| |enter|add student|1| |check|count|1| |
点击保存以后,在Wiki里面点击Test按钮,我们可以看到执行结果如下
简单介绍一下table的设计要点
1.首先要在!Path中声明我们的Fixture的类路径,不要包括包在内
2.先声明是Action Fixture
3.start表示要启动那个Fixture
4.Press是要invoke一个void,且不带参数的函数
5.enter是要invoke一个带有参数的,void的函数
6.check就是对于一个有返回值的函数进行期望值的比较
这样在这个case中,我们先初始化环境,然后给学生人数加1,然后再统计人数看看是不是返回了1.这样一个简单的Action的case就写好了
浅谈Fitnesse框架(四)
Fitnesse已经使用了一段时间了,对Fitnesse也有了一定的了解。正好最近项目开始空了,所以在这里做一个总结。