CSGOpenSource/SpecFlow — pull request #4 by carolynvs (2013-11-22 14:13:29+00:00)
Title: Add plumbing to enable reusable scenarios

This is a first step towards the goal of fully supporting reusable scenarios. The NestedTestRunner class is used by the reusable feature class to bypass the normal setup/teardown that is embedded within a scenario's test method.

Add a constructor to the feature file containing your reusable scenarios (e.g. ReusableScenario.feature.custom.cs)

public partial class ReusableScenarioFeature
{
public ReusableScenarioFeature(ITestRunner runner)
{
testRunner = new NestedTestRunner(runner);
}
}

Add a binding file which defines bindings for the scenarios you would like to reuse.

[Binding]
public class ReusableScenarioSteps
{
private readonly ReusableScenarioFeature _reusableScenario;

public ReusableScenarioSteps(ReusableScenarioFeature reusableScenario)
{
_reusableScenario = reusableScenario;
}

[Given(@"I execute a reusable scenario")]
[When(@"I execute a reusable scenario")]
[Then(@"I execute a reusable scenario")]
public void DoStuffAndThings()
{
_reusableScenario.DoStuffAndThings();
}

Call a the reusable scenario from another feature file.

Feature: Reusable Scenario Tests

Scenario: Execute a reusable scenario
When I execute a reusable scenario