使用Cucumber数据表中的列表

时间:2016-09-18 23:11:38

标签: java testing cucumber

是否可以使用Cucumber数据表中的事物列表?

一个可能的例子是安排会议。 我有一个会议,其中包含我要在验收测试中检查的设定日期,主题和服务员列表。

Feature:
   Scenario:
      Given I want to save a meeting with the following set of data
      | Date | Attendants | Topic
      | 2017-03-12 | Jobs, Steve; Reznik, Trevor | Beer is great
      Then is the data successfully saved

如何正确传递服务员列表进行测试?这有可能吗?我只能找到构成列表的单列表的示例,但我需要嵌套在这里的东西。

2 个答案:

答案 0 :(得分:2)

对于我的测试,我只是像你一样使用一个特殊的分隔符,然后在.rb文件中解析出结果。

A有一个更复杂的例子:

  And there are results:
     | sequence        | user   | steps                       |
     | Style Test 1    | tracy  | 1;0;pass 2;1;fail 4;1;fail  |

我的解析代码如下:

Given(/^there are results:$/) do |table|

  table.hashes.each do |s|

     sequence = Sequence.where(name: s[:sequence]).first
     result = FactoryGirl.build(:sequence_result)
     result.sequence = sequence._id.to_s
     result.user = User.where(name: s[:user]).first._id.to_s

     s[:steps].split(" ").each do |st|
        step = FactoryGirl.build(:step_result)

        parts = st.split(";")
        step.step = sequence.steps[parts[0].to_i]._id.to_s
        step.answer = parts[1]
        step.pass = parts[2] == "pass"

        result.step_results << step
     end

     result.save

  end

end

希望这会有所帮助: - )

答案 1 :(得分:1)

有多种方法可以将小黄瓜表映射到胶水参数:

  • bean列表,请参阅github
  • 上的示例
  • cucumber.api.Datatable
  • 的实例
  • 地图列表
  • 字符串列表