Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete seed data in SpecFlow

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?

like image 237
Leo Avatar asked Dec 07 '10 04:12

Leo


1 Answers

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

like image 119
jbandi Avatar answered Oct 16 '22 04:10

jbandi