【JBehave】表格形式的story参数示例

原创
2016/04/21 17:13
阅读数 430

在实际测试场景中,我们很有可能针对同一场景,有多组参数,这个时候使用在story中使用表格形式的参数,将简化story的编写。

比如登陆,我们的系统有5种角色的账户,我们要执行相应的测试,那么我们的story可能是像这个样子的:

如果角色再来几个,story就会很长,变得比较难维护。

这个时候,我们使用story的表格形式参数的特性,简化story的编写:

最后的story如下:


相应的step代码做一些改动

1、Given注解的value内容和story中的given内容相同

2、相应的参数取值增加@Named注解

@Given("current user uid is [uid] and password is [password]")
public void init(@Named("uid") String uid, @Named("password")String password) {
    System.out.println("init: uid:" + uid + ",password:" + password);
    this.uid = uid;
    this.password = password;
}


高级写法:

我们甚至可以写出类似excel中合并单元格参数形式,在一个表格中内嵌另外一个表格:

Given that Larry has done <trades> trades
Then the traders activity is: 
|name|trades|
|Larry|<trades>|
|Moe|1000|
|Curly|2000|
 
Examples:
|<trades>|
|3000|
|5000|
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
1
分享
返回顶部
顶部