Chapter 11. Behavior-Driven Development

In this chapter, we will cover:

  • Using Cucumber-JVM and Selenium WebDriver in Java for BDD
  • Using SpecFlow.NET and Selenium WebDriver in .NET for BDD
  • Using Capybara, Cucumber, and Selenium WebDriver in Ruby
  • Using Behave and Selenium WebDriver in Python

Introduction

Behavior-driven development (BDD) is an agile software development method that enhances the paradigm of test driven development (TDD) and acceptance tests, and encourages the collaboration between developers, QA, domain experts, and stakeholders. Behavior-driven development was introduced by Dan North in 2003 in his seminal article Introducing BDD. The article can be accessed at http://dannorth.net/introducing-bdd/.

Behavior-driven development focuses on obtaining a clear understanding of desired application behavior through discussions with stakeholders using a ubiquitous language as described at http://behaviour-driven.org/.

It extends TDD by writing test cases in a natural language that non-programmers can read. Users describe features and scenarios to test these features in plain text files using the Gherkin language in the Given, When, and Then structures. You can find out more about Gherkin language at http://en.wikipedia.org/wiki/Behavior-driven_development and https://github.com/cucumber/cucumber/wiki/Gherkin.

The Given, When, and Then structures in the Gherkin language are described as follows:

  • Given: This represents the initial context (precondition)
  • When: This represents the user performing a key action (actor + action)
  • Then: This ensures some kind of outcome (observable result)

In behavior-driven development, the process starts with users of the system and the development team discussing features, user stories, and scenarios. These are documented in feature or story files using the Gherkin language. Developers then use the red-green-refactor cycle to run these features using the BDD framework, then write step definition files mapping the steps from the scenarios to the automation code and re-running until all the acceptance criteria are met.

Tip

Behavior-driven development is also known as acceptance test driven development (ATDD) or story testing.

In this chapter, we will explore how to use frameworks like Cucumber-JVM, SpecFlow.NET, and Capybara, Behave with Selenium WebDriver for behavior-driven development.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.63