Behavior-driven development (BDD) is a relatively new trend in software development and part of agile methodology. BDD itself combines the principles and techniques of Test-Driven Development (TDD) with ideas from Acceptance Test Driven Development (ATDD), domain-driven design, and object-oriented analysis and design to provide all parties involved in software development with shared tools and opportunity to contribute to software development process. BDD approach results into delivery of working and tested software (on Python and Django) that matters.
Main terms of BDD: ubiquitous language, behaviour, user story, etc.
One of its main aims and reasons of creation is to eliminate drawbacks of TDD. One of them is narrowness of TDD in terms of understanding by non-technical personnel. BDD focuses on collaboration between business people, users, business analysts, developers, QA and project managers. Communicating in group of people with so different level of project understanding is a challenge, so inventor of BDD, Dan North, proposed to substitute too technical term ‘test’ to more common ‘behavior’ and use more natural language.
Instead of writing tests (like in TDD), developers should provide specifications and behaviors - how user wants the product to behave. Behavior differs from test by wording. Behavior uses ubiquitous language so that it can be as close to a simple sentence as possible.
Ubiquitous language is a semi-formal language shared by all members of a software development team — both software developers and non-technical personnel. It is the means to develop a shared understanding of the features to be implemented, the business value those features provide as well as a set of acceptance criteria for each feature.
Moreover, creating behaviors as understandable and fluid sentences makes it easy to write better and more comprehensive tests. Acceptance tests in BDD are written using the standard agile framework of a User story that contains a title and a short description in the format: "As a [role] I want [feature] so that [benefit]". Then there has to be a list of scenarios expressed in the form: Given (initial context), When (what actions the user performs), and Then (the desired outcome for the user).
Advantages of BDD:
- Quick learning. BDD approach, in particular the Given-When-Then scheme, is close to everyday language and has a shallower learning curve compared to TDD tools.
- Communication and collaboration. BDD gives development team opportunity to discuss importance, depth and timeline of each feature. Constructive discussion always leads to better understanding and success of the following production and delivery of the product.
- Higher business value. Main place in discussion takes justifying the priority of features by showing their concrete value to business.
- Agile approach. Though ‘agile’ means only partially specified features and undefined requirements, BDD ensures evolving product understanding and system development according to the changing needs.
- Ready documentation. Tools for BDD approach generally provide automatic generation of technical and end user documentation from BDD specifications.
Python BDD tools
- Behave is an open source BDD tool that reads tests in a natural language format and applies Python code to execute it. Test files are written in Gherkin - a human-readable, domain specific language for writing functional (or acceptance) tests. Behave relies on two main components: feature files with behaviour scenarios and step implementations for the scenarios. Feature file describes a feature or a part of a feature in natural language style adding representative examples of possible results.
- Lettuce is an open source BDD tool based on the Cucumber but written in Python. It focuses on common BDD tasks providing developers with the following testing capabilities: to create scenarios describing features in natural language; to assign each scenario with one possible feature; to define steps that will run Python code.
Quintagroup team implemented BDD approach in several projects, since this set of techniques advises on how to develop software focusing on people who will use it. It is one of the best options for Python and Django development. The end product will successfully satisfy customers’ needs.