Hello dear Reader,

Before diving into behavior-driven development (BDD) I will mention mention a highlight to test-driven development (TDD). TDD is a software development process that lies on writing the automated test cases for product workflow before the actual code. Naturally the tests will fail initially, basically the actual code and the workflow will work properly when the tests pass.

BDD is a software development process evolved from TDD and we can say it is an extension of TDD. It uses domain-specific language (DSL) that we call natural or ubiquitous language to illustrate behaviors (how users will interact with the product or what are the expectations of business objectives with the product). As the name say the development thrives to accomplish “desired behavior” of the business objectives. Along all that, BDD is designed to bridge the gap between the technical aspects between the stakeholder (otherwise known product owner or investor) who doesn’t have any coding background, the developer(s) and the code being used on the project. The general idea of BDD is that by using ubiquitous language we generate background code on common language basis. That way we can assure the expected behavior excluding the potential misinterpretation of requirements and specifications.

All involved parties can understand the test cases and their scenarios, the test workflow by reading the steps. The stakeholder doesn’t need to know what a for loop is, what an if condition is, yet the test is described the way that he/she will understand the desired results of tests. That is the goal of BDD, to get the desired behavior but not going to deep into implementation and that way to reach the goals for bot sides (stakeholder – developers). BDD is more business facing, while TDD is more of developer facing testing, although both of them are aiming on implementation using tests.

The general idea of a BDD process looks like:

  • As a Role
  • I request a Feature (Action)
  • To gain an expected Result

The most common and adopted format for examples is Given-When-Then which is the format you will see most used by the BDD community. It follows a very simple structural agreement.

“Given” describes the initial context for the example
“When” describes the action that the actor in the system or stakeholder performs
“Then” describes the expected outcome of that action

BDD consists of some predetermined language, and here I will mention the most commonly used language – Gherkin. Gherkin is a keyword-based, line-oriented language. This means that you are free to use actual ubiquitous language to write down behavior examples. Usually Gherkin language test case consist a Feature and one or more Scenario(s).

Most common description of a feature and a scenario:

Feature: Descriptive text of what is desired

  • In order to realize a named business value
  • As an explicit system actor
  • I want to …
  • Scenario: Some determinable business situation
  • Given some precondition
  • And some other precondition
  • When some action by the actor
  • And some other action
  • And yet another action
  • Then some testable outcome is achieved
  • And something else we can check happens too
  • Scenario: A different situation

Simple example in Gherking of features and scenarios:

Feature: Observing various scenarios

  • Scenario: Observe change1 in our system
  • Given a precondition1
  • When we do something in the system
  • Then we should be able to observe a change1

  • Scenario: Observe change2 in our system
  • Given a precondition2
  • When we do something in the system
  • And we can add some other action
  • Then we should be able to observe a change2

  • Scenario: Observe change3 in our system
  • Given a precondition3
  • When we do something in the system
  • Then we should be able to observe a change3

As you can see by the semi example we can have multiple scenarios under single feature. The good side of Gherkin is the support of all leading programming languages. At the time of writing, there are Gherkin based BDD automation tools written for Ruby, Python, PHP, C#.Net, JS, Java and other languages.

Naturally there are other languages for BDD testing, that I leave to the reader to explore.

Thank you for reading the blog and sincerely hope you enjoyed reading it. If you have any questions, please write us in the comment section anytime.

Posted By Arnold Gergelj

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>