在编写场景时,是否有人有充分的理由选择以下一种风格而不是另一种风格?
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"
如果其他参与者也可以使用相同的功能,则必须定义单独的等效步骤。
就我个人而言,我认为“我”读起来很好(尽管我觉得我知道不是这样)。想法?
最佳答案
两种方式都很好,但有细微的差别。
如果结果的好处是为用户带来的,我有时喜欢用第一人称来表达事物,如果结果是为用户以外的其他人带来好处,则我喜欢用第三人称来表达事物。
例如,您可能有一个故事:
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!
在这种情况下,很明显,与“我应该收到验证码”的想法存在认知脱节,因为它们很烦人,而且没有人想要它们。将这种情况放在第三人称身上,很明显该人可能不会受益。
我偶尔会为用户起名字 - 例如,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.
在其他参与者可以使用相同功能的情况下,他们的角色或权限的上下文将改变行为,并且该上下文无论如何都应该包含在场景中,即使它只是隐含在他们的名称中。
关于cucumber - BDD:显式示例 - 合适的代词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823170/