Digital Transformation & Software Engineering Services
Behavior Driven Development using SpecFlow

Behavior Driven Development using SpecFlow

The Problem:

The test scripts in my very first automation project involved conditional statements, looping, logical, numerical, string operations and much more. Sprint by sprint the software grew more complex and often I got a feeling “aren’t our scripts becoming as complex as the developer code itself?” Despite having a well-designed hybrid automation framework, debugging and reviewing the scripts, translating them back into the business requirements was an onerous task for the business analyst, client and product manager.

The Story Behind:

What if we had an option to define an automation scenario consisting of a few keywords with simple grammar, in a human readable format? Yes, this will definitely reduce the cost of translation as everyone – developers, testers, stakeholders, analysts, product owners and clients – can get involved in the testing process. This will improve the overall communication within a team as well from the team to the client.

The Solution:

Behavior-driven development (BDD) is one such solution which relies on the use of a very specific (and small) vocabulary to minimize miscommunication and to ensure that everyone – the business, developers, testers, analysts and managers – are not only on the same page but using the same words. Cucumber is a tool that runs automated acceptance tests written in a BDD style. Gherkin is the language that Cucumber uses to define test cases.

The Anatomy:

BDD insists that business analysts and developers should collaborate and specify behavior in terms of user stories, which are each explicitly written down in a dedicated document. Each user story should, in some way, follow the following structure:

Banner-Ad-for-Blog-page-1--Digital-ServicesTitle: The story should have a clear, explicit title.

Narrative: A short, introductory section that specifies,

Who is the driver or primary stakeholder of the story?

What effect the stakeholder wants the story to have.

What business value the stakeholder will derive from this effect.

Scenarios: A description of each specific case of the narrative.

Such a scenario has the following structure:

It starts by specifying the initial conditions that are assumed to be true.

It then states which event(s) trigger the start of the scenario.

Finally, it states the expected outcome, in one or more clauses.

What does it cost?

Cucumber is an Open Source tool that runs automated acceptance tests written in a behavior-driven development (BDD) style.

Cucumber is written in the Ruby programming language but its implementations are available for other platforms beyond Ruby, e.g., SpecFlow for .NET

The Essence of SpecFlow:

#1 Specify: Describe the behavior of your system using human-readable syntax. Define specifications in the problem domain using the language of your stakeholders and build up a living documentation of your system

specify

#2 Automate: Bind your test specifications to your application code to automate the testing of your system. Ensure that all your tests pass!

automate

#3 Develop: Run your automated tests periodically to ensure that any changes to your system have not introduced errors. Refactor existing test cases and extend your test suite with new ones as your system evolves with your stakeholders’ needs.

develop1

develop2

Benefits:

  • Better commitment and buy-in
  • Improved focus
  • Better Return on Investment
  • We can move from working in silos to working together

References:

BDD in Action: Behavior-Driven Development for the whole software lifecycle

Instant Cucumber BDD How-to

Cucumber Recipes

Pro Agile .NET Development with Scrum

The Cucumber Book

Specification by Example: How Successful Teams Deliver the Right Software

http://dannorth.net/introducing-bdd/

http://www.specflow.org/

http://cucumber.io/

About the Author

Comments are closed.