As the name suggests, behavior-driven development is based on the desired behavior of the respective software. Thanks to the ubiquitous language, it’s easy for laypeople to prepare certain behavior descriptions. The ubiquitous language comes from domain-driven design (DDD), which – just like BDD – focuses on the application domains. Both approaches consider all involved areas in software development and bring them together independent of frameworks, programming languages, or tools. Using a single language makes this possible.
Nevertheless, even behavior-driven development is unable to completely do without tools and frameworks. That’s because in order for the test cases you define to be translated into executable code, you need to follow a few rules. Descriptions in BDD are not composed as free-flowing text, for example. Using BDD tools like JBehave, Cucumber, or Behat, you can follow a set structure that enables correct implementation. It’s much easier to work with these tools than learn a conventional programming language. Below you’ll find the hierarchical structure you will typically follow in behavior-driven development:
- First, conduct a requirements analysis in which you precisely define the tasks, objectives, and functionalities of the software. Ask yourself or the customer what the software should be able to do.
- After you have identified all the functionalities, these are then described in the form of predefined scenarios. Try to think of all the possible scenarios during which the software should respond with a certain answer.
- Next, specify the expected answer for each scenario in a “Given-When-Then” plan. “Given” describes the software before the test, “When” the action during the test, and “Then” the state of the software after the text.
Depending on which BDD tool you use, the vocabulary may vary slightly, although the principle is the same. Incidentally, these tools are available for the most common programming languages like Java, JavaScript, Python, or Ruby.