2012-10-10 14 views
2

在編寫場景時,沒有人有強烈的論點來選擇下列其中一種風格嗎?BDD:顯式示例 - 適當的代詞?

Feature: Search Product 

As a customer 
I want to search for a product 
So that I can easily locate what I want to purchase 

Scenario: Multiple Products Found (First Person Style) 
Given the following products exist: 
|Product  | 
|Normal Orange| 
|Large Orange | 
When I search for "orange" <--- 
Then the system should display the following products: 
|Product  | 
|Normal Orange| 
|Large Orange | 

或者......

Scenario: Multiple Products Found (Generic Third Person Style) 
Given the following products exist: 
|Product  | 
|Normal Orange| 
|Large Orange | 
When the customer searches for "orange" <--- 
Then the system should display the following products: 
|Product  | 
|Normal Orange| 
|Large Orange | 

或者......

Scenario: Multiple Products Found (Specific Person Style) 
Given the following products exist: 
|Product  | 
|Normal Orange| 
|Large Orange | 
When "John" searches for "orange" <--- 
Then the system should display the following products: 
|Product  | 
|Normal Orange| 
|Large Orange | 

他們似乎都只是做工精細 - 我不知道如果我失去了一個明顯的缺陷,因爲這樣許多例子似乎都爲參與者使用了特定的價值(不僅僅是具體的投入/結果價值)。

我反對使用唯一的參數:

When the customer searches for "orange" 

是獨立的,等效步驟必須被定義,如果其他演員也可以使用相同的功能。我個人認爲「我」讀得相當不錯(儘管我覺得我知道不是)。思考?

回答

3

這是很好的任何方式,但有一個微妙的區別。

我有時喜歡在第一人稱詞語中,如果結果的好處是給用戶的話,第三人稱如果是用戶以外的人。

例如,你可能有一個故事:

In order to prevent bots from spamming the site 
As a moderator 
I want users to prove that they are human. 

和相關方案既可以讀:

Given a user is not registered 
When they try to register 
Then they should be presented with a CAPTCHA 
When they fill in the CAPTCHA 
Then they should be successfully registered 

或者:

Given I am not registered 
When I try to register 
Then I should be presented... what, wait, no, I shouldn't! 

在這種情況下,很明顯因爲他們是「我應該接受CAPTCHA」,所以存在認知上的脫節煩人,沒有人想要他們。把這種情況放在第三人看來,這個好處可能不是那個人的。

我偶爾爲用戶編制名稱 - 例如,普通用戶的Ursula Usual和管理員的Andy Admin。以這種方式使用第三人稱也可以用於調出不同的角色和角色。

還有其他角色相同但兩個不同的人玩的場景。

Given Doctor Donald has filled out Priscilla Patient's prescriptions 
When Doctor Diana looks for her file // <-- different doctor! 
Then she should be able to find those prescriptions. 

在其中的其他角色可以使用相同的功能的情況下,他們的角色或權限的情況下無論如何都會被改變行爲,這種情況下應包含在方案中,即使是在短短的隱他們的名字。

+0

好例子 - 謝謝! –

+0

在第一個示例中,「證明用戶是人」(管理員透視圖)和「註冊帳戶」(用戶視角)這兩個功能是否共存,或者「證明用戶是人類」還是包含(並覆蓋)註冊過程? –

+1

可能會有一個單獨的場景來覆蓋用戶註冊。你可以通過圖形用戶界面重複這個過程,或者破解數據 - 「給定」如何進入它的形式並不重要,因爲這不是你正在鍛鍊的行爲。 – Lunivore

2

我認爲只要開發者和非開發者都喜歡這個故事,我認爲I是很好用的。在頂部你已經澄清,I是一個customer。我不認爲我們關心哪個特定客戶正在進行搜索。

+0

我也這麼認爲。我理解在場景中使用顯式示例的概念(這有助於測試用例),但對於我來說,在上例中,最有意義的是說明哪些產品存在以及要搜索哪些內容。在此示例中,至少指定哪個用戶只是在步驟定義類中生成未使用的方法參數。 –

+1

@TomTom我認爲這實際上增加了困惑;誰是約翰,是否在尋找而不是別人?即使你有一個特殊類型的用戶,我也許只需要改變'As A'來反映並堅持'I'。 – Andy

+0

在這種情況下,不,它不!說得通。 –

1

我認爲它基本上取決於場景。

如果情況是隻涉及客戶的情況,那麼「客戶」可能是最合適的。

如果一個場景可能涉及非客戶類別的用戶,那麼使用「John」(或「Jane」,如果您願意的話)更通用,並且會減少對僅一類用戶的關注。一般來說,系統是爲其他人使用而建立的,所以雖然我同意第一人稱(「I」)風格的讀法很好,但不使用它的心理原因可能是很好的。

當然,我可能完全困惑 - 我對BDD相當陌生。