Integrating SpecFlow and xUnit
NuGet itself does most of the heavy lifting here, but there are a couple of gotchya’s along the way. First, the easy stuff:
- Create a standard Class Library project in Visual Studio.
- Using NuGet, add the packages SpecFlow, xunit and xunit.extensions with either the Package Manager Console or Manage NuGet Packages dialog. xunit.extensions is required for some of the more advanced Gherkin syntax scenarios.
- With this in place, SpecFlow will still generate nUnit tests. To configure it to use xUnit tests, create an app.config file in Class Library project with the following content:
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" /> </configSections> <specFlow> <unitTestProvider name="xUnit" /> </specFlow> </configuration>
That’s it, SpecFlow will now generate xUnit tests which should compile perfectly.
I’ve wrapped all of these steps together into a NuGet package, tentatively titled SpecFlow.xUnit, and contributed it to the SpecFlow project on GitHub. They have just accepted my pull request, so hopefully we’ll see a one click package to integrate these two great libraries on NuGet.org very soon!
Of course, the real beauty of SpecFlow is its Visual Studio integration, which you can install from the Visual Studio Extension Manager. It provides item templates and step debugging on Gherkin .feature files.
I have a few issues with the way that Visual Studio’s Extension Manager works, but that’s another post and has nothing to do with SpecFlow.
– By Nik Molnar