nik codes

Integrating SpecFlow and xUnit

This post is all about getting SpecFlow, my favorite .NET BDD framework, and xUnit, my favorite .NET unit testing framework, playing along nicely together.

NuGet itself does most of the heavy lifting here, but there are a couple of gotchya’s along the way. First, the easy stuff:

  1. Create a standard Class Library project in Visual Studio.
  2. Using NuGet, add the packages SpecFlow, xunit and xunit.extensions with either the Package Manager Console or Manage NuGet Packages dialog.consoledialog xunit.extensions is required for some of the more advanced Gherkin syntax scenarios.
  3. 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.

vsspec

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

Advertisements

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: