2013-02-21 83 views
3

我遇到了编写测试场景的问题,它将检查将添加到数据库的站点的有效性。任何人都可以为我提供一个示例,显示如何正确编写它。不知怎的,我觉得“情景纲要”是不正确的方法...[小黄瓜/ Specflow]:如何编写复杂类型的场景大纲

“站”和“new_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' 的

  • 编号1,因为它的ID不是唯一的
  • 编号3,因为它的名字是不是唯一的
  • ID 4,因为它的代码是不是唯一的

回答

3

我想你可能会混淆你的manys。

A 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 |