Behavior-Driven Development in Bioinformatics
What is BDD?
Behavior-Driven Development (BDD) is a set of Software Engineering practices designed to help teams deliver more valuable and higher quality software features.
It adopts general techniques and principles of Test Driven Development (TDD) with ideas from Domain-driven Design (DDD). BDD incrementally builds functionality guided by expected behavior.
A simple BDD scenario / requirement is as follows:
How does BDD work?
Benefits of BDD
- Understandable by both technical and non-technical people
- Business Analysts (BA) and Subject Matter Experts (SME) can contribute BDD scenarios
- Data can be fed along with the scenarios, which can updated any time without any changes in scripting
- Developers can write the scripts in a language of their choice
- Attractive test reports at the end of the execution [HTML and JSON]
- Availability of Continuous Integration tools like Jenkins, Bamboo, etc…
- Single platform for Web, Mobile, API, thick client, and Database Testing
How BDD fits in an Agile/DevOps environment
After story grooming on the first day of a new sprint, the developer and test teams will agree on frozen acceptance criteria for each user story identified for the sprint. Developers should prepare BDD scenarios as per the acceptance criteria, with the scope being limited to unit-level testing. QA testers or the domain expert will write the functional scenarios for each of the acceptance criteria in the user story. Both Unit and Functional BDD scenarios may or may not contain negative scenarios. Test case design techniques such as Equivalence Partitioning, Boundary Value Analysis, and Decision Tables can be applied while writing the BDD scenarios.
As a best practice, BDD functional scenarios should be sent to the BA or SME for sign-off prior to test scripting. Both development and automation test scripting activities can be carried out in parallel, based on agreement with front-end developers, on how the UI elements on the page look and what the element’s characteristics are for the script to act upon.
For instance, assume the agile team is going to work on a user story for the Europe PMC login screen. Both the UI/front-end developer and QA automation team must agree on a unique element locator like id="login–email"
for the ‘Email’ field, id=login–password
for the ‘Password’ field, etc. (see the figure, below).
Using this technique, the QA team will not have to wait until the development team completes the front-end and back-end development processes to start test scripting. Once the actual build is available for testing, the QA team can run the automated test script and fast track the QA tasks, detecting defects during the early stages of the sprint.
‘Magic’ behind the scenes?
Developers might wonder how plain English text will trigger test execution. The answer to that question is a tool called Cucumber, which is smart enough to parse plain text scenarios. Cucumber will either generate a function skeleton or call the respective function for each step in the given scenario (see below).
Java Steps:
JavaScript Steps:
Ruby Steps:
Once the function skeleton is ready, the script needs to be enhanced according to the step definition using UI automation tools like Selenium, Protractor or Appium as shown below.
In the above example, Java is used along with Selenium and jUnit.
How to parameterize the BDD Test
Reports
By default, Cucumber generates an HTML report, and you can configure a JSON report if you wish. Cucumber-JVM is equipped to convert the JSON report displayed as below in Jenkins using the Cucumber Reports plugin.
The Serenity BDD Framework (a popular Java based open source framework), when used for the BDD implementation, will provide an enhanced report, as shown below.
It is also smart enough to capture a screenshot according to user settings.
TL;DR
Behavior-Driven Development (BDD) is emerged from test-driven software development process that is becoming popular and widely used by Europe PMC and by many organizations, due to its transparency, and the readability of the application behaviour.