【问题标题】:Java Cucumber Step Definition for vertical DataTable垂直 DataTable 的 Java Cucumber 步骤定义
【发布时间】:2013-02-08 23:23:05
【问题描述】:

我正在使用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();
}

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

【问题讨论】:

  • 垂直化的原因是什么?表格的好处是它允许以表格格式简洁地处理多个测试用例。通过限制处理的测试用例数量,垂直化消除了这种好处。
  • 我的标题比记录多,因此无需向右滚动就可以将它们放在我的屏幕上。

标签: cucumber gherkin cucumber-jvm


【解决方案1】:

只需将参数值接收为Map&lt;String, String&gt; 而不是DataTable。 Cucumber 会将第一列转换为映射键,将第二列转换为映射值。

【讨论】:

    【解决方案2】:

    这很简单,因为 Datatable 可以返回一个由字符串组成的数组,您可以以任何您希望的方式逐步执行此操作。

    不过,我同意 Prakash Murthy 的观点,即卧式桌子更常用也更实用。

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多