• about reply
Solidsoft Reply Logo
Menu
  • What we do
  • Pharmaceutical Sector
  • The Solid Blog
  • Newsroom
  • Contact Us
  • about Reply
Solidsoft Reply Logo

Search

Focus On

Blog

System tests using Specflow

Author: Tom Burnip

FOCUS ON: Blog,

Creating tests with Specflow

During a recent BizTalk project, one of the customer requirements was that system tests were to be written using Specflow. Specflow is an open-source framework which ​​allows automated tests to be defined as Behaviour Driven Design (BDD) style specifications. Test scenarios are written using the Gherkin syntax which uses special keywords such as “Given”, “When” and “Then” and enables the scenarios to be written in a non-technical format that is easily understood by developers, testers and business users.

In this blog I will demonstrate how to install Specflow and outline the steps that were used throughout the project to create the tests.

Installing Specflow

Specflow integrates easily with Visual Studio and requires the Specflow extension to be installed.

Open Visual Studio and select Tools|Extensions and Updates, s​elect Online on the left hand side and then enter Specflow in the search box on the right. Click th​​e download button and then click on install:

Specflow blog_Installing Specflow​

Using Specflow

(1) Create a Unit Test project

The first step is to add a Unit Test project to the solution and then use NuGet to download and install​ the Specflow package. There are two ways to do this. The first is to right-click the project and select Manage NuGet Packages for Solution and then click Install:​

Specflow blog_Create a Unit Test project1​​

Alternatively, the package can be installed by selecting Tools|Nuget Package Manager|Package Manager Console and using the following command:

PM> Install-Package Specflow

In order to use the MsTest test provider the generate​d App.config file has to b​e modified as follows:

Specflow blog_Create a Unit Test project2​​​

(2) Create feature files

Specflow uses feature files to describe the feature that is being tested along with the test scenarios. Each scenario consists of a number of steps written in the Gherkin syntax. To add a feature file to the project, right-click it and select Add|New Item and then select Specflow Feature file. Here is an example:

Specflow blog_Create step definitions1​​​​

(3) Create step definitions

Next, create step definitions that bind the steps in the feature files to automation code. There are two ways to generate them:

  • In the code editor, right-click inside the feature file document and select Generate Step Definitions. This option will automatically generate a new class containing a step definition for each of the statements

or​

​
  • Right-click the test project and select Add|New Item and then select Specflow Step Definition

Here is an example of a step definition file:​​​

Specflow blog_Create step definitions2

Note: Right-clicking a step in the feature file and selecting Go To Definition will result in the corresponding step definition being displayed.

Once the steps and step definitions have been created they can be reused in other scenarios.

(4) Create hooks

Hooks enable additional code to be run during the processing of feature and scenarios. There are a number available such as [BeforeTestRun], [BeforeFeature], [BeforeScenari​o] and they are run by adding the relevant tag to a feature or scenario. They can be useful in preparing an environment before test execution as shown by the example below:

Specflow blog_Create hooks​​​​​

(5) Run the tests

The final step in the process is to execute the tests. Ensure the solution builds without error and then open the Test Explorer window. Click Run All to run the tests:​​

Specflow blog_Run the test​​​​​​

Summary

I found Specflow to be a useful framework for creating automated tests. The Gherkin syntax is easy to understand by both technical and non-technical members of the project team. The feature file steps and their associated step definitions can be reused so reduce the amount of time needed to create different test scenarios. Finally, combining Specflow with an open source generator like Pickles, means that living documentation can be created. Pickles uses the Specflow feature files to produce HTML files that are easy to read and navigable and on the customer project this was included as part of the build process.

RELATED CONTENTS

11.07.2017

Blog

Comparison between DPA & GDPR

Before we start comparing, it’s worth highlighting that this is a bit of an “oranges & apples” thing because, technically speaking, the UK DPA (Data Protection Act) 1998 was enacted to bring British law into line with the 1995 EU DPD (Data Protection Directive, aka 95/46/EC) which is the one that is, now, being repealed and superseded by the GDPR (General Data Protection Regulation, aka 2016/679) that was adopted in 2016.

28.07.2017

Blog

MODERN VS TRADITIONAL TECHNOLOGY INTEGRATION

Every business today is looking for ways to unlock the value of their data, connect disparate systems, increase efficiency, optimise the use of current IT while at the same time keeping the organisation secure. Why? Because competitive advantage, positive customer experience and a bulging bottom line are all dependent on it.

20.07.2017

Blog

5 REAL-WORLD DRIVERS OF MODERN INTEGRATION

Technology is becoming increasingly flexible, mobile and connected- the evidence is probably either in your pocket or your hand.
Smart devices are now built around a huge number of modern applications, many of which are tied directly into business functions – in essence the line between consumer and business has blurred.

 
 
 
 
Reply ©​​ 2023​ - Company Information -
 PrivacyCookie Settings​
  • About Reply​​​
  • Inves​tors​​
  • Newsroom
  • Follow Reply on
  • ​
  • ​
​
  • ​About Solidsoft Reply
  • Privacy & Cookies Policy
  • Information (Client)
  • Information (Supplier)​