Setting up a Visual Studio project for testing with NUnit and SpecFlow

In this article I am going to run through my currently preferred set up for Specflow and NUnit. I have already added a new Class Library project named DemoProject.Tests to an empty solution.


Step 1. Install SpecFlow extension for Visual Studio

Once the SpecFlow extension is installed you will be able to add SpecFlow items to a project from the Installed Templates list of the Add Item dialog box.

  1. In the Tools menu select Extension and Updates…. This will open the Extensions Manager dialog.
  2. In the dialog choose the Online gallery in the left pane.
  3. In the right pane type specflow in the search box.
  4. In the middle pane find Specflow for Visual Studio 2013 in the results list and click the Download button. If you already have it installed a tick will be displayed instead of a download button.

specflow-visualstudio-extension
The extension will be downloaded.
specflow-download
Click Install to complete the installation.
specflow-install

You will be prompted to restart visual studio.


Step 2. Install NUnitTestAdapter

This step is optional.  I like to run NUnit tests from within the Test Explorer in Visual Studio rather than running the tests using the NUnit external application.  At this moment NUnitTestAdapter is not compatible with NUnit 3.0 so in the following steps I will ensure NUnit 2.6.* is installed.

Open Package Manager Console and run the following command.

Install-Package NunitTestAdapter -version 2.0.0 -projectname DemoProject.Tests

Step 3. Install the Specflow

Open Package Manager Console and run the following command.

Install-Package SpecFlow -ProjectName DemoProject.Tests

The relevant SpecFlow assemblies will now installed in the specified project.


Step 4. Install Specflow.NUnit

If you run this command without the specific version parameter this will install Specflow.NUnit 2.0.0 which includes NUnit 3.0.0.  As I intend using NUnitTestAdapter (currently only compatible with NUnit 2.6.4) I do not want NUnit version 3 installed so I have specified the -version 1.1.1 parameter, this will install Specflow.NUnit 1.1.1 which includes NUnit 2.6.0.

Open Package Manager Console and run the following command.

Install-Package SpecFlow.NUnit -version 1.1.1 -ProjectName DemoProject.Tests

Step 5. Update NUnit Version
Open Package Manager Console and run the following command.

Install-Package NUnit -version 2.6.4 -ProjectName DemoProject.Tests

This will have updated the NUnit version from 2.6.0 to 2.6.4.


For additional information see the following links:
http://www.specflow.org/resources/
http://www.specflow.org/getting-started/
http://www.specflow.org/documentation/Install-IDE-Integration/
http://ralucasuditu-softwaretesting.blogspot.co.uk/2015/06/write-your-first-test-with-specflow-and.html

Leave a Reply