2013-10-31 32 views
8

我創建一個方案概述類似於下面的一個(這是一個簡化版本,但給我的問題的一個很好的跡象):的多維場景勾勒出Specflow

Given I have a valid operator such as 'MyOperatorName' 
    When I provide a valid phone number for the operator 
    And I provide an '<amount>' that is of the following '<type>' 
    And I send a request 
    Then the following validation message will be displayed: 'The Format of Amount is not valid' 
    And the following Status Code will be received: 'AmountFormatIsInvalid' 

Examples: 
    | type  | description      | amount | 
    | Negative | An amount that is negative  | -1.0 | 
    | Zero  | An amount that is equal to zero | 0  | 
    | ......... | ..........      | .... | 

的例子表提供了測試數據,我需要,但我會以複製測試不同的運營商

Examples: 
    | operator | 
    | op_numb_1 | 
    | op_numb_2 | 
    | op_numb_3 | 

,以避免重複同樣的場景輪廓三次添加另一個示例表與運營商(而不是MyOperatorName)只是名稱;我知道這是不可能的,但我想知道什麼是最好的方法來避免使用三個不同的場景輪廓內的功能,除了運營商名稱相同。 我知道我可以重複使用相同的步驟定義,但我試圖瞭解是否有一個最佳做法,以防止與太相似的場景混淆功能。

回答

8

很高興你知道這是不可能的... 那麼有什麼選擇? 好像有5:

一個:使一個表,每一個選項(叉積)

Examples: 

| type  | description      | amount | operator | 
| Negative | An amount that is negative  | -1.0 | op_numb_1 | 
| Zero  | An amount that is equal to zero | 0  | op_numb_1 | 
| Negative | An amount that is negative  | -1.0 | op_numb_2 | 
| Zero  | An amount that is equal to zero | 0  | op_numb_2 | 
| ......... | ..........      | .... | ...  | 

灣對每個操作員重複場景,輸入行的表格爲 - 但是您說過您不想這樣做。

c。重複每個輸入行的情況下,與運營商表 - 我喜歡這個選項,因爲每個規則是一個單獨的測試。如果確實需要確保每個不同的「運營商」策略實施都通過並且在相同的驗證場景中失敗,那麼爲什麼不將每個驗證場景編寫爲單個場景大綱:例如,

Scenario Outline: Operators should fail on Negative inputs 
Given I have a valid operator such as 'MyOperatorName' 
When I provide a valid phone number for the operator 
And I send a request with the amount "-1.0" 
Then the following validation message will be displayed: 'The Format of Amount is not valid' 
And the following Status Code will be received: 'AmountFormatIsInvalid' 

Scenario Outline: Operators should fail on Zero inputs 
...etc... 

d。重新思考你如何使用Specflow - 如果你只需要關鍵的例子來說明你的特徵(如Gojko Adzic的例子說明所描述的那樣),那麼你通過檢查每個組合來做到過度。但是,如果您使用specflow來自動執行全套集成測試,那麼您的場景可能是合適的......但您可能需要考慮e。

e。編寫集成/單元測試的基礎是您的「操作員」驗證邏輯僅適用於一個地方。如果每個運算符的驗證都是相同的,那麼爲什麼不測試一次,然後讓所有運算符都繼承自或構成相同的驗證器類?

+1

公平地說,'當我爲操作員提供有效的電話號碼'在選項c中是多餘的。 - 你可以寫'當我用一個有效的電話號碼和金額「-1.0」發送請求時。 – perfectionist

+2

好的答案,我肯定會再次@完美主義者,並推低選項d。只是選擇範例來充實你的測試,而不是詳盡地測試每種可能的組合。如果你需要詳盡的測試,然後連接一些可以產生組合測試的東西(請參閱mbUnit),或者只是一個控制檯應用程序,重新使用您的Specflow綁定... – AlSki

+0

感謝@perfectionist,我真的很感謝你的答案;它絕對是完整和詳盡的。 –