The Gherkin-compatible BDD tool that is generally used with .NET is SpecFlow.

We host our .NET client on the NuGet gallery, and it is available through the NuGet Packet Manager Shell:

PM> Install-Package Hindsight.Behave

Alternatively, you can use the built in NuGet Gallery interface from inside Visual Studio 2010/12

Using within a script

You can use the JIRA Connector within your own scripts to download features from Behave:

Using Hindsight.Behave;

public class Demo
    public void Download()
        JiraConnector jc = new JiraConnector("https://behave.pro");
            // The project id of the target project
            project: "10100",
            // The API Key username
            username: "aalyYToxMDgzMjAyMM==",
            // The API Key value
            password: "834a65e809a0ab22696e7e307d222a4887aa0078",
            // Directory to extract features to (relative to script)
            directory: "features",
            // Boolean whether to include manual tests
            manual: true,
            // Boolean whether to verify the SSH certificate
            verify: true,
            // Boolean whether to return feature files that
            // are compatible with NUnit.
            isNUnit: true

This will download all features from project ID 10100 into the features director, including manual tagged scenarios.

Using with MSBuild

You can use the Behave assembly as an MSBuild task as part of your build process. You can modify the build process for a project by "unloading" it in Visual Studio (right click the project in the solution explorer and click "Unload Project") and then right clicking and clicking "Edit {PROJECT}.csproj", or editing the .csproj file directly in the directory for the project.

Create a new reference to the Behave.dll assembly, which will be in your project after using NuGet to install it:

    AssemblyFile="path\to\the\Behave.dll" />

You can then use the Behave task to fetch features, either in one of the existing BeforeBuild or AfterBuild target blocks, or by defining your own as we have below:

<Target Name="Test">
        manual="true" />

Note: Add nunit="true" to the task options if you need to use the NUnit runner. This strips characters from tags (traits) that NUnit doesn't work with.

Step by Step with Visual Studio 2013

This guide will take you from a new solution through to integrating Behave Pro with SpecFlow, and running the feature files.

Visual Studio setup

Install SpecFlow for Visual Studio 2013 from the Extensions and Updates dialog in the Tools menu, and restart Visual Studio when prompted.

Extensions and Updates

Project setup

Create a new solution, containing a project for the Application and a project for the Specs (download the prepared solution file here).

Project overview

Install the Hindsight.Behave, SpecFlow, SpecFlow.NUnit, NUnit, NUnit.Runners and NUnitTestAdapter into your solution, using the NuGet Package Manager from the Tools menu.

NuGet package manager

Configuring MSBuild task

Unload the Specs project, in order to edit the .csproj file (which is the MSBuild configuration used to build that particular project)

Unload Specs project Edit .csproj file

In the .csproj file, uncomment the last section of the root Project element which defines Targets, and add the below code:

    AssemblyFile="..\packages\Hindsight.Behave.0.1.8\lib\Behave.dll" />
<Target Name="BeforeBuild">
        nunit="true />

In the UsingTask block, the AssemblyFile path can be found further up the .csproj file:

Path to Behave.dll

The project, username and password fields can be found from the Project Configuration page in JIRA, as explained in the API Key Setup

Then, reload the project from the Project Explorer.

Fetching and including Feature files from Behave Pro

By building the Specs project, the Feature files will be fetched from Behave Pro. They will not initially be visible in the project explorer, so if you click "Show All Files" you can include the Features directory into the project.

Include fetched Features in project

Generating step definitions

Follow the SpecFlow Getting Started guide to generate Step definitions for all the .feature files that were fetched.

Filtering which scenarios to run

The build tool will download all the features for the project to your local machine. In order to only run certain tests (e.g. by tag, by assignee, by issue), switch the Test Explorer view to Traits.

Tags as Traits

  1. Prev
  2. Next