Endjin - Home

Configuring SpecFlow for XUnit using new-style csproj

by Matthew Adams

[This post is now obsolete – you should look at updating to later versions of SpecFlow]

While you cannot yet use SpecFlow with netcore or netstandard projects, you can use new-style (dotnet) test projects that target net461, and reference netstandard projects-under-test from there.

We like to use XUnit as the underlying test provider in this scenario, and we do the following:

  1. Install the current SpecFlow VS 2017 extension into VS 2017
  2. Create a DotNetCore XUnit test project and perform any package updates offered to you (this handily sets up the VS2017 test environment properly)
  3. Change the <TargetFramework> in the .csproj file from dotnetcore2.x to net461 (or 462, or whatever, but 461 is a good safe lowest common denominator for most scenarios)
  4. Add the SpecFlow.XUnit package to your project
  5. Add an app.config file to configure XUnit code generation
  6. <?xml version="1.0" encoding="utf-8" ?>
        <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
        <language feature="en-US" />
        <unitTestProvider name="xUnit" />
        <runtime detectAmbiguousMatches="true" stopAtFirstError="false"
                missingOrPendingStepsOutcome="Inconclusive" />
        <trace traceSuccessfulSteps="true" traceTimings="false"
            minTracedDuration="0:0:0.1" />

You can now add feature files and generate steps in the normal way.

About the author

Matthew was CTO of a venture-backed technology start-up in the UK & US for 10 years, and is now a Founder of Endjin Ltd, which provides technology strategy, experience and development services to its clients who are seeking to take advantage of Microsoft Azure and the Cloud. You can follow Matthew on twitter.