Visual Studio 2010 Integration
SpecFlow Visual Studio 2010 integration provides many useful features to make the usage of SpecFlow easier.
The Visual Studio 2010 support can be installed from Visual Studio Gallery or from the online search in Visual Studio / Tools / Extension Manager. (You have to search for "SpecFlow" :).
The integration provides the following features:
- Gherkin (feature file) editor with syntax coloring
- Intellisense (auto-completion) for keywords and steps
- Outlining (folding) sections of the feature file
- Highlight unbound steps and step parameters in the editor
- Comment/uncomment feature file lines
- Automatic Gherkin table formatting
- Navigation from scenarios to step definitions: Go To Step Definition (Alt+Ctrl+Shift+S)
- Navigation from step definitions to step usages: Go To SpecFlow Step Definition Usages (Alt+Ctrl+Shift+S)
- Detect bindings from the SpecFlow project, from project references and from assembly references
- Cached step analysis for faster solution startup
- Scenario execution from context menu: Run SpecFlow Scenarios, Debug SpecFlow Scenarios
- Generate step definition skeletons from feature files: Generate Step Definitions
- Re-generate feature files (from project node context menu and automatically on configuration change)
- Configurable options
- Support for ReSharper command shortcuts (when ReSharper is installed): commenting, navigation, test execution
You can find detailed information about some of these features in below.
Navigation from step definitions to step usages (Alt+Ctrl+Shift+S)
With this feature, you can track how your step definitions are used in the feature files. Just place your cursor into a step definition method and invoke "Go To SpecFlow Step Definition Usages" from the context menu or simply press Alt+Ctrl+Shift+S (configurable). You will be given a list of usages that you can use to jump to the feature files immediately.
If you are already in the feature file, you can use the Alt+Ctrl+Shift+S keyboard shortcut (or invoke "Go To Step Definition" from the context menu) to jump back to the code.
Generate step definition skeletons from feature files (with custom templates)
The step definition method declarations (aka step definition skeletons) can be generated from Visual Studio. Select "Generate Step Definitions" from the context menu of the feature file and the appearing dialog will guide you how to create a new binding class with the step definitions for the selected unbound steps. The most common parameter usage patterns (quotes, apostrophes, numbers) are detected so SpecFlow generates the methods and the annotation with the these parameters. You can also choose from different step definition styles, including the new regex-less formats.
Read more about the options and the custom templates in the Step Definition Styles page.
Highlight unbound steps and step parameters in the editor
Do you want to check the binding status of the steps in a scenario? Do you want to have better readable scenarios by highlighting the parameters? This is now possible with this new editor feature: the parameters of the bound steps will be highlighted and unbound steps will be displayed in purple. (You can configure the colors of course.)
Intellisense (auto-completion) for keywords and steps
IntelliSense is one of the feature that makes Specflow easy to use when integrated with Visual Studio. It provides a lists available steps definition and possible sample. It's an auto complete because as you type it suggests based on the typed characters. It does not only displays the steps in the current file but for all "*.feature" files, filtered by what type of step (either Given, When or Then)
As you can see from the Figure 1, the IntelliSense feature pop up (shown with Red Rectangle) in the Given step and it suggests existing (the first two from the IntelliSense pop up) steps from "GetProducts.feature" and "AddProducts.feature". The step has already C# code definition that is why it also specified in the pop-up with "-->" characters
Outlining (folding) sections of the feature file
VS2010 "Edit-->Outlining" menu item works well with Specflow feature file. Even most of the items on "Edit" menu. The "table" in Specflow is also formatted in a nice way with as you type for the column names and values, it automatically expands (shown in figure 3).
Navigation from scenarios to step definitions (Alt+Ctrl+Shift+S)
Another sweet feature is the right-click "Goto Definition" of steps in *.feature file and it will automatically brings you to the C# code steps definition you have (Figure 4). And if the steps definition does not exists it show a message box and ask to copy to clipboard the template steps definition (Figure 5). One thing I notice if the the steps definition is in the partial class and sub-group (like the form1.designer.cs is subgroup of form.aspx) "Goto Definition" does not work