当我编写一个与其他功能使用相同措辞的功能时,如何确保调用正确的步骤来实现持久性?
我正在为某些场景使用相同的措辞编写功能。
Feature: User Management
Scenario: Edit an existing user's details
Given a user exists
在 SpecFlow 中,
Feature: Group Management
Scenario: Add a user to a group's membership
Given a user exists
And a group exists
有没有一种好方法来定义每个功能调用的步骤?我在编写场景时是否以错误的方式处理这个问题?我是否应该硬着头皮更改我给出的陈述以表明它们适用于什么功能?我是 BDD 和 SpecFlow 的新手,因此非常感谢您的帮助。
I am writing features with the same verbiage for some scenarios.
Feature: User Management
Scenario: Edit an existing user's details
Given a user exists
and
Feature: Group Management
Scenario: Add a user to a group's membership
Given a user exists
And a group exists
In SpecFlow is there a good way to define what step each feature calls? Am I going about this the wrong way with my scenario writing? Should I just bite the bullet and change my given statements to denote what feature they apply to? I'm new to BDD and SpecFlow so any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Gherkin 格式(Cucumber 系列中的工具,例如 SpecFlow 使用的格式)没有任何在功能之间共享步骤的结构(在功能内部,您可以使用 背景)。
这背后的含义是特征应该是自描述的并且本身是完整的。通过使用“背景”部分,您可以避免场景太长,但仍将所有信息放在文件中。不过,您必须为每个功能重复共享步骤。
作为替代方案,您还可以创建事件绑定(就像黄瓜中的“钩子”),您可以在其中实现一些分片逻辑。但这个共享逻辑必须在.NET 中实现。
The Gherkin format (that the tools in the Cucumber-family, like SpecFlow uses) does not have any structure for sharing steps between features (inside a feature, you can use backgrounds).
The meaning behind this is that the features should be self-describing and complete in their own. With using the Background section, you can avoid having too long scenarios, but still having all information together in the file. You have to repeat the shared steps for each feature, though.
As an alternative, you can also create event bindings (that is like "hooks" in cucumber), where you can implement some shard logic. But this shared logic has to be implemented in .NET then.