SpecFlow is hands down my favorite testing tool. I’ve been blogging about it since 2013 covering mostly advanced topics. In this post, I’ll go back to the beginning and briefly cover the basics to give you an idea of what it can do.
What is SpecFlow?
SpecFlow is a tool that allows you to:
- Define, manage, and automate human-readable acceptance tests in .NET.
- Enable BDD with easy to understand tests.
- Build up a living documentation of your system.
It consists of two parts: a Visual Studio extension and a runtime delivered via a NuGet package.
The Visual Studio extension is the design-time piece with:
- Gherkin syntax highlighting.
- File templates for features, hooks, and step definitions.
- Executable test generation (code-behind).
You use it to create your tests.
The NuGet package contains the runtime library which executes the tests generated by the Visual Studio extension. The SpecFlow runtime:
- Exposes meta-data about the current tests in the form of the scenario context, feature context, and test thread context.
- Loads a simple dependency injection framework.
- Provides table helper extension methods to make working with tables less painful.
Specify-Bind-Run
Once SpecFlow is installed, you’re ready to specify your first feature.
|
|
Next you bind the Gherkins steps to executable code. Note the Binding
attribute is applied to all binding classes. The Given
, When
, Then
attributes bind to the individual Gherkin steps.
|
|
Finally you run the tests with a test runner. In this case, it’s NUnit.
|
|
Further Reading
For more details on getting started with SpecFlow, check out the excellent documentation. I recommend reading it once when getting started and again after you’ve had some experience. Also, check out my blog posts on SpecFlow.