[Gherkin/Specflow]: 如何使用复杂类型编写场景大纲

3

我在编写一个测试场景时遇到了问题,需要检查将添加到数据库中的站点的有效性。有人能提供一个正确编写测试场景的示例吗?不知何故,我觉得“Scenario outline”不是正确的方式...

'stations'和'new_stations'是复杂类型,我希望已经定义好了'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因为它的代码不是唯一的
1个回答

3

我认为你可能混淆了很多东西。

场景大纲用于以参数化方式描述相同的场景,以便逐个注入值。这看起来像你拥有的第二个表格

但你的例子似乎需要一次性注入许多行已知站点的数据,因此它将变成(请参见表格

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 | 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接