我应该在Gherkin / Specflow Given / When / Then语句中使用什么人和心情?

时间:2016-01-17 14:48:28

标签: cucumber bdd specflow acceptance-testing gherkin

我对使用Gherkin语言编写语句来描述为验收测试执行的各种操作的方式感到困惑。

在一些文章中,人们使用"我"在一些文章中,人们使用" User"。

反应(Then)陈述的情况也是如此:

Case 1 --> xyz page should be displayed
Case 2 --> xyz page is displayed

Ex 1:
Given statement abc
When user performs action A
Then screen xyz should be displayed

Ex 2:
Given statement abc
When I perform action A
Then screen xyz is displayed

写"用户"是否更好?或者"我",最好是写#34;应该是"或"是",以便我的BDD场景可以按照标准呈现和正确?

对任何文章的引用也将是一个很大的帮助。提前谢谢。

1 个答案:

答案 0 :(得分:6)

两者都是正确的,并且有不同的好处。

发明BDD的丹·诺斯说,他更喜欢第一人称(“我”),因为这样他就可以把自己放在用户的位置。但是,他经常使用第三人称(“他/她/客户”),就像他在his introductory article中那样。

第一人称使用有助于使场景符合标准故事模板:

As <a stakeholder>
I want <something>
So that <goal>.

如果利益相关者是用户,则在场景中再次使用“I”是有意义的。

然而,有时情景的结果并不是真正有利于用户的利益。

As the moderator of the site
I want users to prove that they're human
So that I can limit spam.

在这种情况下,将场景放在用户的视角中会很奇怪,因为用户并不真的想要填写该验证码框。我们可能会在这里使用第三人。

Given an odd-looking number "31" on a door frame
When the user identifies the number as "31"
Then the system should authenticate them as being human.

您可能还会发现您有多个利益相关方,其结果非常重要。在这种情况下,将场景置于第三人可以帮助发现可能未包含的任何其他结果或重要利益相关者。

Given Suzanne searches for a taxi for 4pm to take her to hospital
And the estimated price is $23
When she books the taxi
Then she should get a confirmation email
And the driver should be notified of the trip
And she should be charged $23.

因为Suzanne,司机和Uber都参与了这个场景,所以把它们放在第三人身上更有意义。

我倾向于选择第三人,特别是对于有很多场景的大型产品,因为我发现必须切换第一人称角色令人困惑,并且它允许一致性。这也意味着你可以给场景中的演员留下令人难忘的名字,并更容易地谈论它们(例如,Clarence Clumsy在错误中键入他的号码的那个)。

但是,请记住,当您与利益相关者讨论以掌握这些情景时,最重要的是对话。尽可能地写下他们的话,只有在你用Gherkin改写它时才会损害语言。