NGABannerNew1.png

DETAILED READ SECTION

Learn Behavioral Driven Development


What is BDD?


Behavioral Driven Development (BDD) is a software development approach that has evolved from TDD (Test Driven Development). It differs by being written in a shared language, which improves communication between tech and non-tech teams and stakeholders. In both development approaches, tests are written ahead of the code, but in BDD, tests are more user-focused and based on the system’s behavior.


Choosing BDD


TDD works satisfactorily, as long as the business owner is familiar with the unit test framework being used and their technical skills are strong enough, which is not always the case. In these circumstances, BDD has the advantage because the test cases can be written in a common language used by the stakeholders such as, for example, English. This access to clearer, low-jargon communication is probably the biggest advantage to using BDD, making it possible for collaboration between the technical and non-technical teams to run with improved efficiency.


Characteristics of BDD


As described above, the advantage to BDD test cases being written in a common language is that details of how the application behaves can be easily understood by all. For example, test cases can be written using real-time examples of the actual requirements, to explain the behavior of the system.


Essentials to have in place before implementing BDD

  • Requirements should be converted into user stories that can define concrete examples.

  • Each example should be a valid user scenario, rather than a mere test case.

  • An understanding of the ‘role-feature-reason’ matrix and the ‘given-when-then’ formula.

  • An awareness of the need to write ‘the specification of the behavior of a class’ rather than ‘the unit test of a class’.


BDD Frameworks


Cucumber

Cucumber is a test framework that supports BDD. In Cucumber, the BDD specifications are written in plain, simple English which is defined by the Gherkin language. In other words, Gherkin is a language that Cucumber understands. Gherkin presents the behavior of the application used, from which Cucumber can generate the acceptance test cases. Cucumber is a framework developed by Ruby that can work across different technologies.


JBehave

Another popular framework for BDD.


Specflow

Specflow evolved from the Cucumber framework using Ruby on Rails, and is used mainly for .Net projects. SpecFlow also uses the Gherkin language.


BDD Terminology:


1) Feature Files or Story Files:

Feature / Story files are the essential part of BDD which is used to write test automation steps or acceptance tests. This can be used as the live document. The steps are the application specification. All the feature files end with .feature extension. All stories file end with .story extension.


Stories file created in JBehave Framework and Feature files created in Cucumber Framework.


2) Scenario:

Basically, a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”.


Given: As mentioned above, given specifies the pre-conditions. It is basically a known state.

When: This is used when some action is to be performed. As in above example, we have seen when the user tries to log in using username and password, it becomes an action.

Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation.

Background: Whenever any step is required to perform in each scenario th