Behave Pro can export the created Feature and Scenarios to any gherkin compatible test automation tool. For Visual Studio/.NET based projects we have a plugin for MSBuild that integrates into the build process. We host our plugin 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 C# code to download features from Behave:

Using Hindsight.Behave;

public class Demo
{
    public void Download()
    {
        JiraConnector jc = new JiraConnector("https://behave.pro");
        jc.Fetch(
            // The project id of the target project
            project: "10100",
            // The API Key username
            username: "Cloud userId OR JIRA Server Username",
            // The API Key value
            password: "Cloud API key OR JIRA Server Password",
            // 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
        )
    }
}

Note: For Behave Pro Cloud the above URL should be used, but for JIRA Server you need to use your full JIRA Server URL.

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:

<UsingTask
    TaskName="Behave"
    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">
    <Behave
        host="https://behave.pro"
        project="10900"
        username="Cloud userId OR JIRA Server Username"
        password="Cloud API key OR JIRA Server Password"
        directory="Features\"
        manual="true" />
</Target>

Note: For Behave Pro Cloud the above URL should be used, but for JIRA Server you need to use your full JIRA Server URL.

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.

Project setup

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

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

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).

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

...
<UsingTask
    TaskName="Behave"
    AssemblyFile="..\packages\Hindsight.Behave.0.1.8\lib\Behave.dll" />
<Target Name="BeforeBuild">
    <Behave
        host="https://behave.pro"
        project="10900"
        username="Cloud userId OR JIRA Server Username"
        password="Cloud API key OR JIRA Server Password"
        directory="Features\"
        manual="true"
        nunit="true />
</Target>

Note: For Behave Pro Cloud the above URL should be used, but for JIRA Server you need to use your full JIRA Server URL.

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

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.

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.

Did this answer your question?