如何删除 SpecFlow 中的种子数据
这可能已经被提出了,也许是一个愚蠢的问题。
不管怎样,我一直在研究 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用钩子。
挂钩是在执行 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