【问题标题】:Cucumber: Does a Background run before each execution of a Scenario Outline?Cucumber:每次执行场景大纲之前都会运行后台吗?
【发布时间】:2018-06-13 16:38:28
【问题描述】:

给定一个特征文件,如下所示:

Feature: Coffee improves mood in the background

  Background:
    Given the user drank coffee

  Scenario Outline: Coffee changes peoples moods
    Then user <USER> should be <MOOD>

    Examples:
      | USER     | MOOD         |
      |  Michael |  happy       |
      |  Elvis   |  electrified |
      |  John    |  sad         |

后台测试步骤“用户喝咖啡”应该运行1次还是3次?

【问题讨论】:

    标签: cucumber gherkin


    【解决方案1】:

    看看下面的人为答案。在输出中,您会看到后台步骤执行了 3 次。

    feature.rb:

    Feature: Does a background run before each scenario outline?
    
      Background:
        When I'm a background step
    
      Scenario Outline: foo
        Then I should print '<count>'
    
        Examples:
          |count|
          | 10  |
          | 20  |     
          | 30  |   
    

    step_def.rb:

    When(/^I'm a background step$/) do
      print "BACKGROUND EXECUTED"
    end
    
    Then(/^I should print '(\d+)'$/) do |num|
      # empty step
    end
    

    输出:

    Feature: Does a background run before each scenario outline
    
    BACKGROUND EXECUTED  Background:                  # features/login.feature:3
        When I'm a background step # features/step_definitions/login.rb:1
    
      Scenario Outline: foo           # features/login.feature:6
        Then I should print '<count>' # features/login.feature:7
    
        Examples:
          | count |
          | 10    |
    BACKGROUND EXECUTED      | 20    |
    BACKGROUND EXECUTED      | 30    |
    
    3 scenarios (3 passed)
    6 steps (6 passed)  
    

    【讨论】:

    • 谢谢,非常感谢。最重要的是,现在这种现象被记录在案了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多