SpecFlow - Introduction



SpecFlow is an open-source test automation tool built on BDD model. It is mostly used to build automation tests for projects built in .NET. This tutorial will provide knowledge on SpecFlow and its features.

Spec-Flow is primarily developed to build, monitor, and run human-readable acceptance test cases. It is created with Gherkin, which is a plain-text language. SpecFlow has the Gherkin parser which can run over 70 languages. We can execute our tests via SpecFlow’ s in-built test runner and SpecFlow+ Runner.

Components

SpecFlow's primary task is to bind Feature files written in Gherkin. SpecFlow+ Runner is the test runner which has the execution capabilities and reports generation. This also comes without cost and we need to create a SpecFlow account for it.

SpecFlow+ LivingDoc is a group of tools that keeps the Gherkin Feature File in a readable format. This can be shared with the stakeholders in the team who are not well versed with tools like Visual Studio.

SpecFlow+ LivingDoc Generator is a group of plugins and tools for SpecFlow to produce documentation from the Gherkin Feature File. This does not require an account to be created and can be easily shared with others.

SpecFlow+ LivingDoc Azure DevOps allows output to be viewed in the Azure DevOps/TFS. Any user who has the system access can see the specifications when required. It is free but requires a SpecFlow account.

Editing Features in Visual Studio Extension

Besides, SpecFlow has the Visual Studio Extension that gives additional functionalities as described below −

Intellisense (auto-completion) for Steps and Keywords

For easy usage of SpecFlow, intellisense provides the feature to find as we type to restrict the suggestion list. Intellisense is available for Gherkin Files, its keywords and code files as well.

In the Visual Studio, click on Edit, then select Intellisense to get the various options.

Intellisense

The below image shows Intellisense in the Gherkin File.

Intellisense Gherkin

Gherkin Syntax Highlighting

To highlight the keywords, tags, comments, unbounded (purple colour) steps, bounded(black) steps, bounded steps parameter(grey italics).

Feature Files Outline and Comments

In Visual Studio, most of the items in the Edit menu can add value to the Feature files in SpecFlow. We can comment and uncomment specific lines with # character, or with in-built shortcuts like the CTRL+K CTRL+V or CTRL+K + CTRL+V.

There are multiple options from the Edit menu to customize various sections of the Feature file.

Click on Edit, then select the option Outlining.

We can define our own feature file template to open when creating a new test case.

Intellisense case

Formatting Tables

We can modify the table size and format it automatically as we type the names of the column and enter its values.

Formatting Tables

But SpecFlow is not confined to Visual Studio only, it can be used with Mono and VSCode also.

Advertisements