如何在黄瓜中测试具有多个背景的相同功能 [英] How to test for same feature with multiple backgrounds in cucumber

查看:7
本文介绍了如何在黄瓜中测试具有多个背景的相同功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在黄瓜中运行良好的功能(.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

另一种不同的幻想小黄瓜语法:

Alternatively different fantasy Gherkin syntax :

   Background:
     Given I am logged in as an existing supervisee

   Include Scenarios:
     supervisor.features

推荐答案

如果是我,我只会吸重复:

If it was me, I would just suck up the duplication:

http://dannorth.net/2008/06/30/let-your-examples-flow/

另一种方法是在功能上使用一个标签,表明您要针对两个用户组运行场景.然后使用 Around 钩子运行场景两次,每种类型的用户一次.

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.

我们之前讨论过背景大纲之类的东西,但我们得出的结论是,实施它不值得额外的复杂性.

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屋!

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