2012-01-12 58 views
1

我已經得到的specflow測試屈指可數的步驟,是這個樣子:我應該如何命名我的一個場景輪廓

Scenario: Person is new and needs an email 
Given a person 
And the person does not exist in the repository 
When I run the new user batch job 
Then the person should be sent an email 

Scenario: Person is not new and needs an email 
Given a person 
And the person does exist in the repository 
When I run the new user batch job 
Then the person should not be sent an email 

除,而不是僅僅2的情況,我有10級非常相似的場景,所有的步驟都是這樣,所以我想使用「場景大綱」。不幸的是,我很難用一種可讀的方式來重寫我的步驟。

目前,我已經想出了這一點,但看起來笨重:

Scenario: Email batch job is run 
Given a person 
And the person '<personDoes/NotExist>' exist in the repository 
When I run the new user batch job 
Then the person '<personShould/NotGetEmail>' be sent an email 

Examples: 
| !notes | personDoes/NotExist | personShould/NotGetEmail | 
| Exists | does not   | should     | 
| No Exist | does    | should not    | 

我也認爲是本,而它是清潔不達意近也

Scenario: Email batch job is run 
Given a person 
And the person does exist in the repository (is '<personExist>') 
When I run the new user batch job 
Then the person should be sent an email (is '<sendEmail>') 

Examples: 
| !notes | personExist | sendEmail | 
| Exists | false  | true  | 
| No Exist | does  | false  | 

有沒有人有更好的參數化方法,如「是」,「不」,「應該」,「不應該」,「有」,「沒有」?在這一點上,我正在考慮把所有東西都作爲一個不同的場景,因爲它更具可讀性。

+0

你目前有10個測試...看起來並不像很多,除非測試本身有很多步驟 - 如果它們確實有很多繁瑣的步驟,我們可能能夠將測試按摩成形,以便表格和場景概述變得過度。你可能會發佈一個實際測試作爲一個例子(最複雜的測試?),並突出變體測試中的變化? – perfectionist 2012-01-28 07:54:12

回答

1

這是我在過去所做的那樣:

Given these people exist in the external system 
| Id | First Name | Last Name | Email | 
| 1 | John  | Galt  | x  | 
| 2 | Howard  | Roark  | y  | 
And the following people exist in the account repository 
| Id | External Id | First Name | Last Name | 
| 45 | 1   | John  | Galt  | 
When I run the new user batch job 
Then the following people should exist in the account repository 
| External Id | First Name | Last Name | Email | 
| 1   | John  | Galt  | x  | 
| 2   | Howard  | Roark  | y  | 
And the following accounts should have been sent an email 
| External Id | Email | 
| 2   | y  | 

可以使用table.CreateSet()和table.CreateSet()在SpecFlow輔助方法來快速轉動表到數據的假外部系統存儲庫和數據庫中的帳戶表。

然後你就可以在數據庫中使用table.CompareToSet(accountRepository.GetAccounts()比較表中的「那麼」條款的記錄。

整潔的事情是,所有的你寫的步驟可重複使用的多種情況。所有你要做的就是改變表中的數據,並SpecFlow爲您編寫測試。

希望幫助!

0

也許你應該將它們分成兩種情況

Scenario Outline: User exists in the repository 
Given a person 
| Field | Value | 
| First | <first> | 
| Last | <last> | 
And the person exists in the repository 
When the user attempts to register 
Then the person should be sent an email 

Examples: 
| first | last | 
| Bob  | Smith | 
| Sarah | Jane | 

然後是另一種情況。這使得情景意義非常清晰。如果你的通用步驟是通用的,你可以重複使用它們。我也嘗試來自用戶的方法

相關問題