如何删除 SpecFlow 中的种子数据

发布于 2024-10-06 05:33:54 字数 147 浏览 4 评论 0原文

这可能已经被提出了,也许是一个愚蠢的问题。

不管怎样,我一直在研究 SpecFlow 并想知道如何删除该功能的种子数据。这些种子数据在不同场景中共享。有没有一种优雅的方法来做到这一点?也许能够在调用 testRunner.OnFeatureEnd() 时注入事件?

This may have already been brought up, a stupid question perhaps.

Anyway, I have been looking into SpecFlow and wondering how I can delete my seed data for the feature. This seed data are shared across different scenarios. Is there an elegant way of doing this? Perhaps the ability to inject an event when testRunner.OnFeatureEnd() in invoked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

╰ゝ天使的微笑 2024-10-13 05:33:54

您可以使用钩子。

挂钩是在执行 Gherkin 功能期间在特定时间执行的方法。

执行过程中有多个针对不同事件的钩子。

在 SpecFlow 中,您可以在 [Binding] 类中使用特殊属性定义挂钩。
可以使用以下钩子:

[BeforeTestRun]、[AfterTestRun]、
[功能前]、[功能后]
[场景之前]、[场景之后]、
[场景块之前]、[场景块之后]、
[BeforeStep]、[AfterStep]

示例:

https://github.com/techtalk/SpecFlow-Examples/blob/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests.Selenium/StepDefinitions/BookSteps.cs

< a href="https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooksSteps.cs" rel="noreferrer">https://github.com/techtalk/SpecFlow/blob/主/测试/FeatureTests/BeforeAfterHooks/BeforeAfterHooksSteps.cs

You can use hooks.

Hooks are methods that are executed at certain times during execution of Gherkin features.

There are several hooks for different events during the execution.

In SpecFlow you define hooks in your [Binding] classes with an special attribute.
The following hooks are available:

[BeforeTestRun], [AfterTestRun],
[BeforeFeature], [AfterFeature]
[BeforeScenario], [AfterScenario],
[BeforeScenarioBlock], [AfterScenarioBlock],
[BeforeStep], [AfterStep]

Examples:

https://github.com/techtalk/SpecFlow-Examples/blob/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests.Selenium/StepDefinitions/BookSteps.cs

https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooksSteps.cs

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