首页 技术 正文
技术 2022年11月6日
0 收藏 456 点赞 750 浏览 2870 个字

FIT是fitnesse使用的默认的引擎(SLIM的使用在上一篇文章中说明),不需要特别声明即可使用执行表格测试,所有编写的fixture都需要继承Fit的Fitxture

编写测试用例前需要先声明class或者jar包所在的路径,才能找到所需要的fixture

使用关键字path

Fitnesse FIT的使用

1. Column Fixture

这是使用最多的,每一行代表输入或者期望输出,添加?的代表调用的输出方法,如果期望值和实际输出值一致,则显示绿色,否则显示红色,并且显示实际输出值。如果添加的是()表示返回值,值的颜色是灰色;addRemovePayerFixture在包fixture下,调用的时候需要加上包路径

Fitnesse FIT的使用

源码:

public class AddRemovePlayerFixture extends ColumnFixture {

private String playerName;

private Game theGame;

public void setPlayerName(final String playerName) {

this.playerName = playerName;

}

public boolean addPlayer() {

this.theGame = StaticGame.theGame;

Player thePlayer = this.theGame.addPlayer(this.playerName);

return this.theGame.playerIsPlaying(thePlayer);

}

public int countPlayers() {

return this.theGame.getNumberOfPlayers();

}

}

输入的playerName会调用set方法载入输入值

2. Row Fixture

用于查询数据的fixture,只要输入了查询的条件就可以获得返回,也可以校验输出的返回值,这种表格适用于查询数据

Fitnesse FIT的使用

源码

public class EmployeePayRecordsRowFixture extends RowFixture {

public Object[] query() throws Exception {

EmployeePayRecord[] records = new EmployeePayRecord[2];

records[0] = new EmployeePayRecord(1, 1000, “Bob”);

records[1] = new EmployeePayRecord(2, 2000, “Jack”);

return records;

}

public Class getTargetClass() {

return EmployeePayRecord.class;

}

}

public class EmployeePayRecord {

public int id;

private double salary;

public String name;

public EmployeePayRecord(final int id, final double salary, final String name) {

this.id = id;

this.salary = salary;

this.name = name;

}

public double pay() {

return this.salary;

}

}

fixture先通过getTargetClass()加载查询的数据对象,然后通过query获得查询结果,整个fixture的作用就是组装数据,

查询的时候从左往右匹配条件,如果前面的列值没有找到对应的数据,则会标记为fail,查询结果中,没有期望的值,则会标记为miss,期望值不在查询结果中,则会标记为surplus

Fitnesse FIT的使用

3. Action Fixture

当想要操作一系列的方法的时候,可以使用该fixture

操作的类型主要有三种enter,press,check

enter: 一般适用于set方法,把期望的值传递给fixture

press:执行方法,参数可选

check:需要输入期望值

Fitnesse FIT的使用

源码:

public class CountFixture extends Fixture {

private int counter = 0;

public void count() {

this.counter++;

}

public int counter() {

return this.counter;

}

public void setCounter(final int num) {

this.counter = num;

}

}

4.Table Fixture

当fit提供的fixture不能满足需要的时候,可以使用table fixture,该fixture可以自由处理表格单元格的

(0,0)表示左上角第一个单元格

(row,column)都是从0开始

Table fixture的方法

protected abstract void doStaticTable(int rows)

Table   Fixture is an abstract class that   you must derive from. You must override doStaticTable to perform the   functions of the fixture. The number of rows in the table is passed in rows.

protected Parse getCell(int row, int column)

Returns the addressed table   cell as a Parse.

protected String getText(int row, int column)

Returns the text within the   addressed table cell.

protected boolean blank(int row, int column)

Returns true if the   addressed table cell is blank.

protected void wrong(int row, int column)

Turns the addressed table   cell red.

protected void right(int row, int column)

Turns the addressed table   cell green.

protected void wrong(int row, int column, String actual)

Turns the addressed table   cell red, and annotates it with the actuall value.

protected void ignore(int row, int column)

Turns the addressed cell   gray.

protected int getInt(int row, int column)

Converts the addressed cell   to an int, and returns it.

官网上的例子:http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.FitFramework.TableFixture

上一篇: 9517 Link Link Look
下一篇: C++一些知识难点
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905