Pro tips for SpecFlow and your C# code!

Advanced tips for SpecFlow and Behavior-Driven Development in .NET

We are going to look at things like ScenarioContext, setup and teardown, navigation inside the IDE, and using arguments in step definitions.

xeladu
Level Up Coding
Published in
3 min readFeb 2, 2022

--

Photo by Markus Spiske on Unsplash

You may have seen my other post about Behavior-Driven Development with .NET, which is a tutorial on how to set it up for you. In this article, I am going to give further tips beyond the basics that will increase your ability to write good tests and debug failing tests faster.

Using ScenarioContext/FeatureContext

The ScenarioContext is a state object that lives as long as a scenario runs. You can use it as a Dictionary<string, object> to pass data between steps, so you don’t need to define private fields in your step classes.
To access the ScenarioContext, inject it into the binding class and save a reference to it.

--

--