Click here to Skip to main content
Click here to Skip to main content
Technical Blog

How-to : End to End automated testing with Specflow

, 28 May 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
End-to-End testing is about testing a full “slice” of an IS, from user input to tiers (DB, service provider) and back to the system output. For this concern, at Betclic, we use 2 tools : Specflow : it’s a Behavior…Read more ›

<!-- dt { text-decoration: underline; } figcaption { font-style: italic; } -->End-to-End testing is about testing a full “slice” of an IS, from user input to tiers (DB, service provider) and back to the system output.

For this concern, at Betclic, we use 2 tools :

Quick Behavior Driven Design glossary

Spec (specification) :
Description of how an information system should behave
Feature :
Part of an Information System, that have it”s own behavior
Scenario :
Part of a feature
Step :
Atomic operation of a scenario

Setup

Visual studio extensions
Fisrt of all, install the Specflow VS extension.
specflow extension
specflow extension for VS 2013
Nuget packages
In your target test project, add the following packages

  • PM> Install-Package SpecFlow
  • PM> Install-Package Selenium.WebDriver
  • PM> Install-Package NFluent
App.config
By default, Specflow use NUnit. As the recommended test framework is MSTest, you have to tune the concerned config section

    <specFlow>
        <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/docun-config -->
        <unitTestProvider name="MsTest" />
    </specFlow>
Files organisation
At the of the Test project, add a “Specs” and a “Steps” folders.The first one will hold the Gherkin files, the second one will contain the associated transcription of spec into C#

First test

Description

Let say we want to test the navigation of our menu bar.
In a default MVC Website, I added a new “StaticContent” controller, and added a link to it in the layout’s menu.
We wanty to check if a click on this link browse to the target page.

Gherkin

First, we create a “specification” in Gherkin langage

Right-click on the Specs folder and add a new SpecFlow Feature file :

Add a Feature File
Add a Feature File

And name it “Navigation”. This file will specify all the business navigation rules over your website.
Add the following content :

Feature: Navigation 	In order to browse the site 	As an user 	I want to use the naviagtion bar Scenario: Browse to StaticContent page 	Given I am on the home page 	When I click on StaticContent link in navigation bar 	Then I should land on StaticContent page
A feature and its first scenario

Pretty self-describing, isn’t it? The main advantage of the Gherkin language is that everybody, from Business to QA people have the same understanding of it.
By sharing a common language, we are able to efficiently communicate, and build a system that purely reflects the business needs. Even better, you can build thoses specifications with the business and QA.

Translate to steps

By right-click in the feature file and select “Generate Step definition”, you will launch an wizard tool that will create the step file skeleton.

Target the “Steps” folder before generate the steps ;-)

You should have a new test file with 3 blocks :

Default step file skeleton
Default step file skeleton

Our scenario implies the use of a browser. Here comes WebDriver, that allow us to abstract the communication with the browser.

For this, we start by sharing the same instance of browser execution between the different steps of our secnario :

Browser initialize and tear down
Browser initialize and tear down

Now we are able to “web-drive” our browser with a easy API :

Steps implementation
Steps implementation
It’s a simple transcription of the scenario :
Given : Initial state, load the default page of the website
When : description of an action, here, the click on the StaticContent page’s link
Then : the expected state : ie do we had browse to the StaticContent page ?

Run the test : a “web-driven” Firefox window will be launched by WebDriver/Selenium, and perform few actions.

Test explorer result window
Test succedeed!

Conclusion

In this article, we saw how to setup a functionnal environment for starting Behavior Driven Design on web application.

To achieve this we rely on the pair Specflow / WebDriver.

More to come about WebDriver API, stay tuned!

Share
facebooktwittergoogle_plusredditlinkedinmail

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Betclic Tech
Chief Technology Officer Betclic
France France
I am Head of Software Development at Betclic France. I manage the Paris Dev Team, consisting of 35+ talented people, in various technical and functional projects in the fields of sports betting, poker, casino or horse betting.
 
Check out our technical blog at https://techblog.betclicgroup.com
Group type: Organisation

3 members

Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 29 May 2014
Article Copyright 2014 by Betclic Tech
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid