Exploring BDD with Specflow | Sparks
1111
post-template-default,single,single-post,postid-1111,single-format-standard,ajax_fade,page_not_loaded,,qode-title-hidden,qode-child-theme-ver-1.0.0,qode-theme-ver-9.3,wpb-js-composer js-comp-ver-4.12,vc_responsive

Exploring BDD with Specflow

Introduction on BDD

One of the biggest challenges faced by development teams today is understanding and implementing the exact requirements of the product owner. Dan North’s amazing software development method BDD (Behaviour Driven Development) reduced the requirements knowledge gap between product owners and developers. In addition, it bridged the domain knowledge gap between developers and testers. Also, it reduces the cost of translation and rework. Through this development process, the business will gain a more accurate product rather than a product filled with messy code and full of bugs.

BDD provides the following benefits:

  • The product owner can obtain a product matching the exact requirements.
  • The product owner will provide the requirement with examples that make it easy to develop and test.
  • Minimizes the domain and technical knowledge gap between testers and developers.
  • Tests/Scenarios are written in a human-readable format. Therefore, it is easy to read and write tests.
  • Tests/Scenarios are written according to the behavior of the application and divided into features.
  • Tests will verify the exact business requirements implemented.
  • Easy to implement test automation.

Test Automation industry is gaining a lot of advantages through BDD. Several testing tools got introduced along with BDD. Some of the famous ones are JBehave and Cucumber. Specflow is also one of them which is currently gaining the attention of a lot of automation testers. In all of these frameworks, gherkin syntax will be used to write the feature files.

Getting started with Specflow

What is Specflow?

This is called cucumber for .net. As cucumber, it allows users to write feature files/user stories in human-readable formatted gherkin syntax. This is an open-source tool. Therefore, all the technology seekers are welcome to give a try. Visual Studio is recommended to use along with it since the tool is based on .net. Additionally, the VS Debugger will be an added advantage.

Set up in 5 mins with Visual Studio

Pre-Conditions for setup

  1. Install Visual Studio (Community Edition will be enough/ Latest Version)
  2. .NET framework should be installed (Latest Version)

Pre-Conditions for setup

  1. Navigate to Manage Extensions in order to install Specflow
  2. Install Specflow (Configure according to the Visual Studio version installed)

Exploring BDD with Specflow

Tips and Tricks to write handy feature files

Feature files are considered to be the most important when it comes to the BDD. Scenarios should be simple and should not contain any complex steps. Regardless of the domain expertise, any individual starting from a product owner to a developer should be able to understand any scenario. Below are some tips and tricks which I follow when writing feature files,

  • Use clear simple sentences when writing feature files
  • Include repetitive testing steps in the Background block
  • Use parameterizing rather than hard coding the values inside step files
  • Use Data tables to give multiple values to the parameters
  • Use scenario Outline to run the same test over and over with different parameters
  • Use tags to group test scenarios according to the environment or the test suite
  • Don’t include all the scenarios in one feature file. Always divide it and include a set of related scenarios in one feature file.

Note: Feature files are supported to write in many natural languages other than English

The structure of a feature file is as follows.

Exploring BDD with Specflow

The main structure will be divided into Feature, Background, and Scenarios. There are several keywords which give different meanings and they are explained below,

  1. Feature – Describes the specific functionality/feature of the application
  2. Background – This will contain a collection of pre-conditions to be run before each scenario in the file
  3. Given – Describes pre-condition steps
  4. Scenario – Explains the identified test scenario
  5. And – Describes conditions
  6. When – Describes actions
  7. Then – Describes expected results

Example of Scenario Outline

Exploring BDD with Specflow

Project Structure

There is no recommended way for the project structure. However, the project should be manageable and easy to re-work. Below is a sample project structure,

Exploring BDD with Specflow

The project can be divided into Page Objects, Specifications containing the feature files and another folder containing the step definition files. App.config file will define the chrome driver and the unit test provider for the project. RunSettings files can be used to store different URLs, usernames, and passwords and re-use when writing the tests.

Writing your first test
Follow the steps in the video to write your first test.

Finally, this is a wonderful technology which will make our daily work much more exciting. Keep learning more about Specflow and BDD. There is more to discover and learn. As Dan North says “BDD is not about conversations, it’s about shipping working, tested software that matters, using conversations.”


Sajitha Dissanayake is a Trainee Associate QA Engineer  at Zone24x7. You can also follow her on LinkedIn.

No Comments

Post A Comment