The Visual Studio integration includes the following features to make it easier to edit feature files and identify which steps have already been bound.
Gherkin Syntax Highlighting¶
Various default styles have been defined for the Gherkin syntax. You can customise these colours in Visual Studio’s settings (Tools | Options | Environment | Fonts and Colors). The names of the corresponding Display items in the list begin with “Gherkin”.
In addition to highlighting keywords, comments, tags etc., unbound steps and parameters in feature files are highlighted when editing the file in Visual Studio. The following syntax highlighting is used by default:
- Purple: unbound steps
- Black: bound steps
- Grey italics: parameters in bound steps
You can thus tell immediately which steps in a feature file have been bound.
IntelliSense (auto-completion) for Keywords and Steps¶
IntelliSense makes SpecFlow easy to use when integrated with Visual Studio. IntelliSense uses find-as-you-type to restrict the list of suggested entries.
IntelliSense is available in feature files for the following:
- Gherkin keywords (e.g.
- Existing steps are listed after a
Thenstatement, providing quick access to your current steps definitions. Bound steps are indicated with “–>”. Note that all the steps in all “*.feature” files that match the current type (Given, When, Then) are displayed:
The IntelliSense suggestions for the Given step includes existing Given steps feature files. The entries in the list that are indicated with “–>” indicate that the step has been bound.
IntelliSense is also available for the Gherkin keywords in your code files.
As much as having a suggested list of previous entries could speed up your work, the list may become too long in a big project and not really usable. To fix this problem, SpecFlow gives you the option to limit the number of IntelliSense step instances suggestions for each step template.
To do this, simply navigate to Tools | Options | SpecFlow | General | IntelliSense and set the desired number of suggestions you wish to see against the Max Step Instances Suggestions value:
> Note: Setting this value to 0 will only show the template.
Outlining and Comments in Feature Files¶
Most of the items in the Edit menu work well with SpecFlow feature files, for example:
- You can comment and uncomment selected lines (’#’ character) with the default shortcut for comments (Ctrl+K Ctrl+C/Ctrl+K Ctrl+U) or from the menu
- You can use the options in the Edit | Outlining menu to expand and contract sections of your feature files
Tables in SpecFlow are also expanded and formatted automatically as you enter column names and values:
Document formatting is also available. It automatically re-indents code and fixes blank lines, comments, etc.
You can find this option under Edit->Advanced->Format document or alternatively use the Ctrl+K, Ctrl+D shortcut:
Below is a feature file document which is not indented correctly:
Format Document command:
You can globally rename steps and update the associated bindings automatically. To do so:
- Open the feature file containing the step.
- Right-click on the step you want to rename and select Rename from the context menu.
- Enter the new text for the step in the dialog and confirm with OK.
- Your bindings and all feature files containing the step are updated.
Note: If the rename function is not affecting your feature files, you may need to restart Visual Studio to flush the cache.