SpecFlow gives complete Visual Studio debugger support, allowing setting of breakpoints on Given/When/Then lines in the feature files and step through their execution. All step definitions are implemented in any.NET language. When a project containing SpecFlow feature files is compiled, the output is a NUnit test assembly. It is added automatically to all unit test projects by Visual Studio to help it quickly find projects with tests. If your tests don't appear in Visual Studio, the first thing to try is closing your solution and then re-opening them. There appear to be bugs in Visual Studio not detecting changes to projects when you edit them.
![Support Support](/uploads/1/2/6/2/126292234/345069856.png)
Note: If you are new to SpecFlow, we recommend checking out the Getting Started guide first. It will take you through the process of installing SpecFlow and setting up your first project and tests in Visual Studio.
SpecFlow consists of three components:
- The IDE Integration that provides a customized editor and test generation functions within your IDE. This is provided as an extension for Visual Studio.
- The generator that can turn Gherkin specifications into executable test classes, available from NuGet.
- The runtime required for executing the generated tests. There are different runtime assemblies compiled for different target platforms. These packages are also available from NuGet.
In order to install everything you need, you first have to install the IDE integration and then set up your project to work with SpecFlow using the NuGet packages.
Installing the IDE Integration
The process of installing the IDE Integration packages depends on your IDE. If you are using Visual Studio, the easiest way is to search for “SpecFlow” in the online search in the extension manager (Tools | Extensions and Updates). For other IDE integrations and for the direct download links, see the Install IDE Integration page.
This step only needs to be performed once in Visual Studio.
Project Setup
The generator and runtime are usually installed together for each project. To install the NuGet packages:
- Right-click on your project in Visual Studio, and select Manage NuGet Packages from the menu.
- Switch to the Browse tab.
- Enter 'SpecFlow' in the search field to list the available packages for SpecFlow.
- Install the required packages. You need to install the SpecFlow NuGet package (
SpecFlow
). Other helper packages are also availble, e.g.SpecFlow.NUnit
orSpecRun.SpecFlow
. We recommend that you install the NuGet packages for your test framework.
You can also install NuGet package manager console, e.g.:
Refer to the NuGet Integration page a full list of supported NuGet packages. You can find more details on setting up your project on the Setup SpecFlow Projects page.
Conflicts with Deveroom
If you are using Deveroom, do not install the SpecFlow Visual Studio extension; you should only install one of these 2 extensions.
Enable Extension
If Visual Studio displays the error message
Cannot find custom tool 'SpecFlowSingleFileGenerator' on this system.
when right-clicking on a feature file and selecting Run Custom Tool
, make sure the SpecFlow extension is enabled.To enable the extension in Visual Studio, select Tools | Extensions and Updates..., select the 'SpecFlow for Visual Studio' extension, then select Enable.
If the error still occurs, select Tools | Options | SpecFlow and set Enable SpecFlowSingleFileGenerator Custom Tool to 'True'.
Enable Tracing
You can enable traces for SpecFlow. Once tracing is enabled, a new
SpecFlow
pane is added to the output window showing diagnostic messages.To enable tracing, select Tools | Options | SpecFlow from the menu in Visual Studio and set Enable Tracing to 'True'.
Troubleshooting
Steps are not recognised even though there are matching step definitions
The SpecFlow Visual Studio integration caches the binding status of step definitions. If the cache is corrupted, steps may be unrecognised and the highlighting of your steps may be wrong (e.g. bound steps showing as being unbound). To delete the cache:
- Close all Visual Studio instances.
- Navigate to your
%TEMP%
folder and delete any files that are prefixed withspecflow-stepmap-
, e.g.specflow-stepmap-SpecFlowProject-607539109-73a67da9-ef3b-45fd-9a24-6ee0135b5f5c.cache
. - Reopen your solution.
You may receive a more specific error message if you enable tracing (see above).
Tests are not displayed in the Test Explorer window when using SpecFlow+ Runner
Note: As of Visual Studio 2017 15.7 the temporary files are no longer used. The following only applies to earlier versions of Visual Studio.
The Visual Studio Test Adapter cache may also get corrupted, causing tests to not be displayed. If this happens, try clearing your cache as follows:
- Close all Visual Studio instances
- Navigate to your
%TEMP%VisualStudioTestExplorerExtensions
folder and delete any sub-folders related to SpecFlow/SpecRun, i.e. that have 'SpecFlow' or 'SpecRun' in their name. - Reopen your solution and ensure that it builds.
Unable to find plugin in the plugin search path: SpecRun` when saving / generating feature files
SpecFlow searches for plugins in the NuGet packages folder. This is detected relative to the reference to
TechTalk.SpecFlow.dll
. If this DLL is not loaded from the NuGet folder, the plugins will not be found.A common problem is that the NuGet folder is not yet ready (e.g. not restored) when opening the solution, but
TechTalk.SpecFlow.dll
in located in the binDebug
folder of the project. In this case, Visual Studio may load the assembly from the binDebug
folder instead of waiting for the NuGet folder to be properly restored. Once this has happened, Visual Studio remembers that it loaded the assembly from binDebug
, so reopening the solution may not solve this issue. The best way to fix this issue is as follows:- Make sure the NuGet folders are properly restored.
- Close Visual Studio.
- Delete the
binDebug
folder from your project(s). - Reopen your solution in Visual Studio.
Tests are not displayed in the Test Explorer window when using SpecFlow+ Runner, even after after restoring the NuGet package
The
SpecRun.Runner
NuGet package that contains the Visual Studio Test Explorer adapter is a solution-level package (registered in the .nugetpackages.config
file of the solution). In some situations, NuGet package restore on build does not restore solution-level packages.To fix this, open the NuGet console or the NuGet references dialog and click on the restore packages button. You may need to restart Visual Studio after restoring the packages.
VS2015: Tests are not displayed in the Test Explorer window when using SpecFlow+ Runner
It seems that VS2015 handles solution-level NuGet packages differently (those registered in the
.nugetpackages.config
file of the solution). As a result, solution-level NuGet packages must be listed in the projects that use them, otherwise Test Explorer cannot recognise the test runner.To fix this issue, either re-install the SpecFlow+ Runner NuGet packages, or add the dependency on the
SpecRun.Runner
package (<package version='1.2.0' />
) to the packages.config file of your SpecFlow projects. You might need to restart Visual Studio to see your tests.