Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top