如何在SpecFlow中删除种子数据

Leo*_*Leo 6 bdd integration-testing acceptance-testing specflow

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

无论如何,我一直在研究SpecFlow并想知道如何删除该功能的种子数据.此种子数据在不同方案中共享.这样做有一种优雅的方式吗?也许是在调用testRunner.OnFeatureEnd()时注入事件的能力?

jba*_*ndi 8

你可以使用钩子.

钩子是在执行Gherkin特征期间的某些时间执行的方法.

在执行期间,有几个钩子用于不同的事件.

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

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

例子:

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