Fitnesse 之 Script Table

纯属转载


Fitnesse 之 Script Table

在表中每一行代表一个执行脚本。

第一行中的Script关键字表明表格类型,后面紧跟着类名(Fixture)和构造函数中的参数。在一个测试页中如果没有再指定其它Fixture,将一直沿用上一个Fixture。

 

(1)Fixture调用方法

scriptlogin dialog driverBobxyzzy

或者

Script:login dialog driverBobxyzzy  

 

 

(2)函数调用
Most instructions involve some kind of function call. By default, the name of the function is assembled from tokens in every other cell. The arguments of the function are the intervening cells. Appending ";" to the end of a function name in a cell invokes sequential argument processing, which means that the arguments to the function are all subsequent cells.

 

 

函数调用有两种方法

1. Interposing Function Call (Default) 插入函数调用(默认)

login with usernameBoband passwordxyzzy  

 

2. Sequential Argument Processing Function Call顺序参数处理函数调用

login with username and password;Bobxyzzy  

注意:这种方式需要在函数名后追加一个“;”。

 

(2)行操作和显示

1. 如果一个行中只单独存在一个函数,如果这个函数返回值是布尔值,那么该行将变成红色(false)或者绿色(true),其他的保持本色。

2. 关键字:

第一个行单元格

类型

 

check

返回匹配情况

后面紧跟着一个函数,行最后一个单元格将被作为预期值,与函数的返回值进行匹配,匹配为true,不匹配为false

check out

返回不匹配情况

后面紧跟着一个函数,行最后一个单元格将被作为非预期值,与函数的返回值进行匹配,匹配为false,不匹配为true(与check相反)

ensure

布尔值

后面紧跟着一个函数,这个函数必须返回一个布尔值。如果是false,行为红色,如果是true,行为绿色。

reject

(非)布尔值

后面紧跟着一个函数,这个函数必须返回一个布尔值。如果是false,行为绿色,如果是true,行为红色。(和正常的显示相反)

note/blank/以#和*开头的单词

忽略

表示忽略该行

show

展示

后面紧跟着一个函数,在函数被执行后,该行的最后面将被增加一个单元格,用于展示函数的返回值。

Symbol(标识符)

变量

和$符连用,它将存储后面函数的返回值

start

新建

后面紧跟着另一个Fixture以及构造函数参数,它将代替前面的Fixture,下面的行将使用新的Fixture。

 

例子:

Fixture代码:

复制代码
public class LoginDialogDriver
 {
//四个成员变量
  private String userName;
  private String password;
  private String message;
  private int loginAttempts;
//构造函数
  public LoginDialogDriver(String userName, String password) {
    this.userName = userName;
    this.password = password;
  }
//使用用户名和密码登录方法
  public boolean loginWithUsernameAndPassword(String userName, String password) {
    loginAttempts++;
    boolean result = this.userName.equals(userName) && this.password.equals(password);
    if (result)
      message = String.format("%s logged in.", this.userName);
    else
      message = String.format("%s not logged in.", this.userName);
    return result;
  }
//返回登录信息
  public String loginMessage() {
    return message;
  }
//返回登录次数
  public int numberOfLoginAttempts() {
    return loginAttempts;
  }
}
复制代码

 

测试表格:

scriptlogin dialog driverBobxyzzy
login with usernameBoband passwordxyzzy
checklogin messageBob logged in.
rejectlogin with usernameBoband passwordbad password
checklogin messageBob not logged in.
check notlogin messageBob logged in.
ensurelogin with usernameBoband passwordxyzzy
notethis is a comment
shownumber of login attempts
$symbol=login message

表格说明:

第一行:创建LoginDialogDriver对象

第二行:调用loginWithUsernameAndPassword方法

第三行:调用loginMessage方法,对比当前的登录信息是否是Bob logged in

第四行:调用loginWithUsernameAndPassword方法,使用的是错误的密码

第五行:调用loginMessage方法,对比当前的登录信息是否是Bob not logged in

第六行:调用loginMessage方法,对比当前的登录信息是否不是Bob logged in

第七行:调用loginWithUsernameAndPassword方法,判断返回值

第八行:忽略该行

第九行:调用numberOfLoginAttempts,并在该行的最后面将被增加一个单元格,展示返回值。

第十行:调用loginMessage方法,并将登录信息保存到变量symbol中


出自http://www.cnblogs.com/moonpool/p/5530494.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值