如何在黄瓜中测试多个背景的相同功能 [英] How to test for same feature with multiple backgrounds in cucumber
问题描述
我有一个功能(.feature文件),在黄瓜中正常工作。
I've got a feature (a .feature file) that are working fine in cucumber.
功能中所有方案的背景只是设置一个用户,然后以管理员身份登录,例如
The background of all the scenarios in the feature just sets up a user, and then logs in as a supervisor, e.g.
Background:
Given I am logged in as a supervisor with an existing supervisee
...loads of scenarios
但是,应用程序的设计/目标已更改,并且无论您是以管理员身份登录,作为用户。对于主管/用户的设计不对称的大多数应用程序的其余部分,这是不正确的。
However the design/goals of the application has changed and the same scenarios should all work whether you are logged in as a supervisor or as the user. This is not true for most of the rest of the application where the design is not symmetrical for supervisors/users.
有任何合理的方法,以避免复制和粘贴整个的特征文件有不同的背景?它似乎没有一种方法来参数化背景(例如与一个Either:或:节),或者一种方法拉入一个外部文件加载的方案。想法?
Is there any sane way to avoid copying and pasting the whole of the feature file with a different background? It doesn't seem like there's a way to either parameterize background (e.g. with an Either: Or: stanza) or alternatively a way to pull in an external file with a load of scenarios. Ideas?
Background:
Given I am logged in as an existing supervisee
...same loads of scenarios
这里有一些幻想小黄瓜的语法>
Here's some fantasy gherkin syntax (that doesn't exist)
Background Outline:
Given I am logged in as a <user>
Backgrounds:
| user |
| supervisor with an existing supervisee |
| an existing supervisee |
...loads of scenarios
或者不同的幻想Gherkin语法: / p>
Alternatively different fantasy Gherkin syntax :
Background:
Given I am logged in as an existing supervisee
Include Scenarios:
supervisor.features
推荐答案
我只会吸引重复:
http://dannorth.net/2008/06/30/let-your-examples-flow/
将在功能上使用标记,指示您要针对这两个用户组运行方案。
An alternative would be to use a tag on the feature that indicates you want to run the scenarios against both user groups. Then use an Around hook to run the scenario twice, once for each type of user.
之前我们讨论过Background Outlines这样的事情,但是我们得出的结论是,是不值得执行它的额外的复杂性。
We've talked about things like Background Outlines before, but the conclusion we came to was that it wouldn't be worth the extra complexity to implement it.
这篇关于如何在黄瓜中测试多个背景的相同功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!