当我编写一个与其他功能使用相同措辞的功能时,如何确保调用正确的步骤来实现持久性?

发布于 2024-09-17 06:51:13 字数 413 浏览 5 评论 0原文

我正在为某些场景使用相同的措辞编写功能。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-09-24 06:51:13

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文