垂直DataTable的Java Cucumber步骤定义

时间:2013-02-08 23:23:05

标签: cucumber gherkin cucumber-jvm

我正在使用cucumber-jvm。我在.feature文件中有以下内容:

  Background:
    Given the following account file line:
      | First Name     | Lance  |
      | Last Name      | Fisher |
      | Corporate Name |        |

这是一个垂直方向的表。以下生成的步骤定义使用First Name和Lance作为标题,其中First Name,Last Name和Corporate Name应为标题。

@Given("^the following account file line:$")
public void the_following_account_file_line(DataTable arg1) throws Throwable {
    // Express the Regexp above with the code you wish you had
    // For automatic conversion, change DataTable to List<YourType>
    throw new PendingException();
}

如何实现步骤定义来处理垂直表而不是水平表?

2 个答案:

答案 0 :(得分:4)

只需将参数值作为Map<String, String>而不是DataTable接收。黄瓜会将第一列转换为地图键,将第二列转换为地图值。

答案 1 :(得分:2)

这很简单,因为Datatable可以返回一个字符串数组数组,你可以以任何你想要的方式逐步执行它。

但是,我同意Prakash Murthy的说法,水平表更常用,更实用。