【问题标题】:[Gherkin/Specflow]: How to write a scenario outline with complex types[Gherkin/Specflow]:如何编写具有复杂类型的场景大纲
【发布时间】:2013-02-21 11:19:49
【问题描述】:

我在编写测试场景来检查将添加到数据库中的站点的有效性时遇到问题。任何人都可以为我提供一个示例,说明如何正确编写它。不知怎的,我觉得“场景大纲”不是正确的方法......

'stations' 和 'new_stations' 是复杂类型 我想拥有已经定义的“站”,并检查是否可以添加每个“新站”。

Scenario Outline: 
    Given We have <stations>
    And We are trying to add a station of the <new_stations> having the same id, the same name or the same code
    Then we should not be able to add it


# <stations>
        | Id | Code | Name     | Validity                      |
        | 1  | 1    | City 1   | from 2013-01-01 to 2013-04-01 |
        | 2  | 2    | City 2   | from 2013-03-15 to 2013-05-01 | 

# <new_stations>
        | Id | Code | Name   | Validity                      |
        | 1  | 234  | City 4 | from 2013-03-01 to 2013-07-01 |
        | 3  | 5    | City 1 | from 2013-03-01 to 2013-07-01 |
        | 4  | 2    | City 3 | from 2012-03-15 to 2013-07-15 | 

因此不应添加任何“new_stations”

  • Id 1,因为它的 Id 不是唯一的
  • Id 3,因为它的名称不是唯一的
  • Id 4,因为它的代码不是唯一的

【问题讨论】:

    标签: testing bdd specflow gherkin


    【解决方案1】:

    我认为你可能混淆了你的许多。

    scenario outline 用于描述相同的场景,但以参数化的方式,以便依次注入值。这看起来像您拥有的第二张桌子

    但是您的示例看起来像您需要一次为已知站点注入多行数据,因此它将变为(请参阅tables)

    Scenario Outline: 
      Given We have 
        | Id | Code | Name     | Validity                      |
        | 1  | 1    | City 1   | from 2013-01-01 to 2013-04-01 |
        | 2  | 2    | City 2   | from 2013-03-15 to 2013-05-01 | 
      And We are trying to add a station <Id>, <Code>, <Name>, <Validity> 
      Then we should not be able to add it
    
    Examples:
        | Id | Code | Name   | Validity                      |
        | 1  | 234  | City 4 | from 2013-03-01 to 2013-07-01 |
        | 3  | 5    | City 1 | from 2013-03-01 to 2013-07-01 |
        | 4  | 2    | City 3 | from 2012-03-15 to 2013-07-15 | 
    

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 2011-07-04
      • 2015-11-23
      • 2014-10-12
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多