SpecFlow And .NET Core

Note: Support for .NET Core is only available from SpecFlow 3 onwards.

Setting up SpecFlow to work with .NET Core projects in SpecFlow 3 is different from configuring projects using .NET Framework in previous versions of SpecFlow.

For details on the general configuration of SpecFlow, see Configuration.

Prerequisites

Microsoft.NET.Test.Sdk 15 or higher is required. If you have not installed the SDK, please do so.

Ensure Your Visual Studio Extension is Up-to-date

The SpecFlow Visual Studio with support for .NET Core is not compatible with versions of SpecFlow prior to 2.3.2. If you have disabled automatic updates for the extension, please enable the automatic updates again to upgrade to the newest version.

To do so:

  1. Select Tools | Extensions and Updates from the menu in Visual Studio.
  2. Enter “SpecFlow’ in the search field to restrict the entries in the list.
  3. Click on the “SpecFlow for Visual Studio” entry and enable the Automatically update this extension check box.
    Automatically update this extension
  4. This will prevent newer versions of the extension from being installed automatically. Once you are ready to upgrade to SpecFlow 3, you can enable this option again.

Configuring the Unit Test Provider

The configuration is no longer in your app.config file. Instead, the unit test provider is now configured using plugins for the desired test frameworks. You will therefore need to add one of the following NuGet packages to your project to configure the unit test provider:

  • SpecRun.SpecFlow-3.1.0
  • SpecFlow.xUnit
  • SpecFlow.MsTest
  • SpecFlow.NUnit

Note: Make sure you do not add more than one of the unit test plugins to your project. If you do, an error message will be displayed.

To add the required packages:

  1. Right-click on your project, and select Manage NuGet Packages.
  2. Enable the Include prerelease option and search for “SpecFlow”.
  3. Install/update the following packages as required:
    • SpecFlow
    • SpecFlow.Tools.MsBuild.Generation
    • One of the unit test provider packages (see above).
  4. Install the test runner for your unit test provider (e.g. xunit.runner.visualstudio).

Configuration Options

When using .NET Core, configuration options must be configured in the new specflow.json configuration file. This file is optional when using the Full Framework.

The structure of the .json configuration file reflects the structure of the old app.config. Some examples can be found here.

Example: The following sets the feature file language is set to “de-AT”.

{
    "language":
    {
        "feature": "de-AT"
    }
}

For more details, refer to the configuration section.

Generating Code-behind Files with MSBuild

You need to use the SpecFlow.Tools.MsBuild.Generation NuGet package to generate the code-behind files, see here.

Sample Projects

.NET Core versions of the example projects are located here.