Skip to main content

Search...

A critical look at BDD

BDD looks simple, but it's not. Why Gherkin without real team communication creates more effort than benefit, and how to do it right.

9 min read
Cover for A critical look at BDD

Behavior Driven Development (BDD) is a method in which requirements specialists, developers and testers jointly formulate test cases in a syntax that can be read by everyone, typically Gherkin. The core is a standardized language throughout the entire project cycle. In practice, BDD often fails because teams only write test cases in Gherkin afterwards instead of using the method as a communication tool from the outset.

Key Takeaways

  • Gherkin syntax alone is not BDD: If you only translate test cases into Gherkin after development, you lose the only real advantage, namely the common language from requirement to test.
  • BDD scenarios should describe a single behavior and, as a guideline, comprise five to seven steps so that they remain readable and maintainable even months later.
  • Completely covering the acceptance test with BDD creates technical debt: Squeezing long UI step sequences into Gherkin makes test cases more incomprehensible, not more understandable.
  • Every feature file is code and must be maintained like code; underestimating this means adding an additional abstraction layer to the project without realizing the communication benefits.

What Behavior Driven Development actually means

Behavior Driven Development, or BDD for short, is an approach in which the entire team formulates requirements in such a way that they can be used directly in testing. The idea dates back to around 2006 and is therefore not a new trend, even if it often appears to be.

The core is a cycle, similar to the test-driven approach, which starts with the requirement. Requirements specialists, developers, testers and colleagues from the test infrastructure work on a common vocabulary and use it to write test cases in a syntax that everyone can read. The Gherkin format is common, but there are other ways.

These test cases are then processed in the sprint or in the respective development process. Test automation can start in parallel. Ideally, there will be many green tests at the end, and the team will have the same level of knowledge and the same language from the requirement to the test.

The real benefit is the common language

The biggest advantage of BDD is a common language throughout the entire project cycle. Andreas Döring, test automation expert and advocate of the method, sees this as the core.

Without this common basis, the usual divergence occurs: The business demands something, development implements a slightly different reading, individual special cases are understood differently. The testers arrive at the end of the chain and have to pack up the differences that have long since arisen.

BDD is actually a very obvious, very good approach. I just sometimes see a few practices that I find difficult to believe are good. Andreas Döring

Projects almost always fail because of communication, not technology. This is exactly where BDD comes in, by bringing the coordination process to the beginning and forcing a common understanding before code is created.

Why BDD makes no sense at the end of the process

If you only write your test cases in Gherkin at the very end, you haven’t done BDD, you’ve just written test cases in a different notation. This is precisely the most common misuse: Requirements are created in some tool, development is done, and QA sits down at the end to write requirements again.

This means that the actual benefit is lost. The common language cannot be subsequently smuggled into a process that was running without it. At this point, the developer no longer benefits from it, the child has fallen into the well.

There is nothing wrong with Gherkin as a pure test case format if it helps the tester. It becomes problematic if you add an additional abstraction layer to the automation that only exists for you. APIs, user interface and infrastructure have to be addressed anyway. Adding a layer on top that nobody else uses costs time and effort without any value in return.

Every Gherkin step is code that needs to be maintained

BDD looks simple, and that is precisely the trap. A readable syntax tempts management to introduce it because it looks so uncomplicated. But what looks simple is not simple.

Every feature file is code, comparable to a Java class, and must be handled just as carefully. The art is in the details: how do you write the feature files, with which syntax, with which parameters, where do you store the test data? This is initially additional work, and this work needs to be included in the project planning right from the start.

Andreas draws a comparison with the Scrum manifesto. It only takes a few pages to read, but it takes years for the team to reach maturity. There is no correlation between the simplicity of the presentation and the simplicity of implementation.

A scenario describes exactly one behavior

A good scenario describes a single behavior, not a complete process. How many scenarios belong to a user story varies: In the best case it is a 1-to-1 matching, in many special cases it will be three, four, five or more.

Andreas gives five to seven steps per test case as a guideline for the length. There is no standard that prescribes this. Two principles from clean code serve as a guide: “don’t repeat yourself” and “keep it simple, stupid”.

Long constructs with stacked when and then steps over ten or fifteen lines are a warning signal. If a test case fills an entire A4 page, it is neither comprehensible nor fun six months later. Such cases arise when you do BDD just for BDD’s sake.

The better way is to break down large processes into small steps. Recording and filing a document is one step. For this step, you can think carefully about which special cases exist. If you work your way through the process in this way, you will have covered every part at the end without having to test the entire process in one go.

Describe behavior, not control elements

Test cases should remain at the behavioral level and not map the specific user interface. Instructions such as “open the dropdown” or “enter in the input line” do not belong in a feature file because such details are constantly changing.

Anyone who specifies the UI down to the control element will rewrite their feature files every time a dropdown changes or an input field is added. No business analyst enjoys maintaining the interface to this level of detail.

The right level of abstraction asks: What happens in the system? Which states need to be passed through, which boundary conditions apply, what needs to be considered from a legal perspective? This level is completely sufficient and remains stable while the interface continues to develop.

Clarity arises before automation

The greatest value of BDD is created on the way to syntax, not just during the green test. Formulating a requirement in Gherkin forces the requester, tester and developer to think through together what the requirement is actually trying to achieve and how it works.

In a sense, a feature file is a model that emerges from the prose text or the original idea. The fun and the gain in knowledge lie in creating this model. The test automation behind it is then an additional benefit, not an end in itself.

A clear sequence follows from this. If requirements management is already working in the team and everyone is talking to each other, it is worth taking the step towards a common language. If this communication is missing, it is the first problem that needs to be solved long before talking about syntax. Otherwise, you only formalize your own free text requirements and gain nothing.

How to introduce BDD in your project without making a mistake

Start small and not with the big acceptance test. Find a manageable module, preferably in the backend instead of the frontend, and gain experience in your specific environment.

Tutorials only help to a limited extent. They teach you the syntax, but do not answer the question of how BDD works for you. A small proof of concept in your own context will show you more quickly which interfaces and tools you are working with and what effort you are really putting in.

The prerequisite is a functioning team that also includes the product owner or business analysts. At the start of the sprint, consciously take the time to formulate a requirement in the chosen syntax. If it works in one component, you can expand it and also tackle overarching topics, such as marrying frontend and backend in integration testing.

There is scope for the format. In addition to the classic Given-When-Then scheme, Andreas calls the tool Gauge, in which tests are written in Markdown. This is freer than Gherkin, but pursues the same goal: to write something that is readable for everyone.

The toolchain is secondary, the connection to the specialist site is not

There is no clear best framework for the tools, almost all of them work. Cucumber, the Serenity framework, JBehave and Gauge are mentioned. Which one you choose is less important than the question of how it fits into your existing automation.

What is important is the classification: BDD tools are always just one layer above the actual tool stack. You still need and maintain Selenium, API tools and the rest of the infrastructure. The BDD framework does not replace any of this, it comes on top of it.

The bigger challenge lies in connecting the business side. Requirements are often created in tools such as Jira. Plugins such as X-Ray connect such tools with Gherkin so that the feature files can be exported and transferred to the pipeline.

It is worth considering the parties involved. Developers and automation specialists can easily work with their IDEs and plugins in IntelliJ or Visual Studio Code. A department that is used to web interfaces, on the other hand, will be shocked if it suddenly has to maintain feature files in a development environment. Those who work with web interfaces and Jira are better off with a solution like X-Ray because it picks up the specialist side where it is already working.

BDD is not a panacea

BDD has many advantages, but it is not a tool that solves problems by itself. The key message is that what looks simple still needs to be maintained, and in the worst case scenario, BDD brings an additional source of technical debt into the project.

If you approach this consciously, start small and really put the common language before the development, you will gain a strong method. If you attach Gherkin at the end of the process as a compulsory exercise or force everything into Given-When-Then with a sledgehammer, you are building up effort without benefit.

Share this page

Related Posts