应该是嫩黄瓜场景总是有步骤吗? [英] Should Gherkin scenario always have When step?

查看:178
本文介绍了应该是嫩黄瓜场景总是有步骤吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在Gherkin中定义场景时,有时在Given和When步骤之间没有明确的区别,即用户没有与系统的主动交互,并且验证的目的是验证系统在某些情况下应当如何看待。

When defining scenarios in Gherkin sometimes there is no clear distinction between Given and When steps, i.e. there is no active interaction with the system from the user and the purpose of the validation is to verify how the system should look under certain circumstances.

请考虑以下方面:

Scenario: Show current balance
Given user is on account page
Then user should see his balance

p>

vs

Scenario: Show current balance
When user goes to account page
Then user should see his balance

我不知道我会一直使用第二个变种。如果我有多个方案共享上下文用户在帐户页面,其中一些有额外的用户操作,而其他人不,所以在我看来应该是有效的保持用户在帐户页面作为一个步骤即使在某些情况下可能缺少时间。这是一个有效的方法吗?

I am not sure I would always use the second variant. If I have multiple scenarios sharing the context "user is on account page" and some of them have additional user actions while others don't, then it seems to me it should be valid to keep "user in account page" as a Given step even though it may lack "When" for some scenarios. Is this a valid approach?

推荐答案

正式和技术上,Cucumber / SpecFlow不需要你写一个时间步骤,给定/ When / Then's只是按它们在场景中写入的顺序执行。在这方面,你不需要一个时间步骤。

Formally and technically Cucumber/SpecFlow doesn't require you to write a When-step or rather Given/When/Then's are just executed in the order they are written in the scenario. In that regard you don't need a When-step.

但是,正如Andy Waite所写的那样,时间步骤显示了您的系统从安装程序进入新状态的操作或事件在Then步骤中验证。在这方面,每一个测试都应该有一个时间步骤(如你写的:我们在其他方面测试)。

But, as Andy Waite wrote about, the When-step shows on the action or event that your system takes from the "Setup" to get to the new state that you verifies in the Then-step. In that regard a When-step should be present in every test (as you wrote: what are we testing otherwise).

这会留下你最后的评论;如果验证只是设置(假定系统已启动,那么数据库是干净的作为一个朴素的例子)。在这种情况下,可以跳过时间步。

That leaves your final comment; what about verifying just the setup (Given the system is started, Then the database is clean as a naïve example). In such scenarios the When-step could be skipped.

所以,一如既往,归结于可读性和理解。情景是为了使我们对系统行为的思考具体和清晰。使用优化的表单来理解和了解相关行为。

So, as always, it comes down to readability and understanding. Scenarios are written to make our thoughts about the systems behavior concrete and clear. Use the form that optimize for understanding and learning about the behavior in question.

没有太大的想法,我可能会猜到,一般的建议是总是使用一个时间步骤,使事件或行为非常明显和清晰。如果可能,我会避开隐性和隐性行为。

Without thinking too hard on this I would probably guess that the general advice is to always use a When-step that makes the event or behavior very apparent and clear. I would shy away from implicit and hidden behavior when possible.

我希望这有助于。

这篇关于应该是嫩黄瓜场景总是有步骤吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆