2013-02-21 57 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 |