How to set up Specflow and NUnit v3 in Visual Studio 2015. I have already added a new Class Library project named SpecFlowTest to an empty solution.
Step 1. Install SpecFlow extension for Visual Studio 2015
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.
- In the Tools menu select Extension and Updates…. This will open the Extensions Manager dialog.
- In the dialog choose the Online gallery in the left pane.
- In the right pane type specflow in the search box.
- In the middle pane find Specflow for Visual Studio 2015 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.
The package will be downloaded
A dialog will appear with a summary on the installation and prompting confirmation of the install
The installation will complete.
Once installed a web page normally opens in Visual Studio with this address, http://www.specflow.org/guidance/first-steps. In some cases a restart of Visual Studio may be required.
Step 2. Installing NuGet packages
As usual NuGet packages can be installed via the window interface
Tools > NuGet Package Manager > Manage NuGet Packages for Solution…
or if you prefer, via the command line
Tools > NuGet Package Manager > Package Manager Console
There are a few ways to add the SpecFlow and NUnit libraries to a project, either by installing individual packages for each product or by using combined packages.
Option 1. Combined Package
Open NuGet Package Manager and locate the SpecFlow.NUnit package. This option will install both the SpecFlow and NUnit libraries as well as the NUnit runners for running the tests from TestExplorer in Visual Studio. In the package description it does say NUnit version 2.6+ will be installed, at the time of this post NUnit version 3.0.0 was installed. In the future this may be a newer version of NUnit.
And to install via command…
Install-Package SpecFlow.NUnit
Although NUnit version 3.0.0 is installed it can be upgraded to the latest version. At this time the current version is 3.4.1.
And the NUnit update via command
Update-Package NUnit
And with that everything should be good to go.
Option 2. Installing Individual Packages
The packages can be installed separately. Doing so would allow you to install a different test runner or a different unit testing framework. Whatever the reason, if that is the case then you can follow these steps.
Install SpecFlow
With NuGet Package Manager open search online for the SpecFlow package.
And via command
Install-Package SpecFlow
Install NUnit
This will install version is 3.4.1, no need for update.
And via command
Install-Package NUnit
Install NUnit3TestAdapter
Here I am installing a different test runner to the one installed in the combined package. The result is the same, tests can be run from within Test Explorer.
Install-Package NUnit3TestAdapter
If feature files have already been added to the project the below message will prompt for them to be re-generated.
Conclusion
It seems logical to use the SpecFlow.NUnit combined package if NUnit is the unit test framework of choice. If you will be using MSTest or a different test runner installing separate packages is not that much more work.
You must be logged in to post a comment.