Question

Test Driven Development has been the rage in the .NET community for the last few years. Recently, I have heard grumblings in the ALT.NET community about BDD. What is it? What makes it different from TDD?

Was it helpful?

Solution

I understand BDD to be more about specification than testing. It is linked to Domain Driven Design (don't you love these *DD acronyms?).

It is linked with a certain way to write user stories, including high-level tests. An example by Tom ten Thij:

Story: User logging in
  As a user
  I want to login with my details
  So that I can get access to the site

Scenario: User uses wrong password

  Given a username 'jdoe'
  And a password 'letmein'

  When the user logs in with username and password

  Then the login form should be shown again

(In his article, Tom goes on to directly execute this test specification in Ruby.)

The pope of BDD is Dan North. You'll find a great introduction in his Introducing BDD article.

You will find a comparison of BDD and TDD in this video. Also an opinion about BDD as "TDD done right" by Jeremy D. Miller

March 25, 2013 update

The video above has been missing for a while. Here is a recent one by Llewellyn Falco, BDD vs TDD (explained). I find his explanation clear and to the point.

OTHER TIPS

To me primary difference between BDD and TDD is focus and wording. And words are important for communicating your intent.

TDD directs focus on testing. And since in "old waterfall world" tests come after implementation, then this mindset leads to wrong understanding and behaviour.

BDD directs focus on behaviour and specification, and so waterfall minds are distracted. So BDD is more easily understood as design practice and not as testing practice.

There seem to be two types of BDD.

The first is the original style that Dan North discusses and which caused the creation of the xBehave style frameworks. To me this style is primarily applicable for acceptance testing or specifications against domain objects.

The second style is what Dave Astels popularised and which, to me, is a new form of TDD which has some serious benefits. It focuses on behavior rather than testing and also small test classes, trying to get to the point where you basically have one line per specification (test) method. This style suits all levels of testing and can be done using any existing unit testing framework though newer frameworks (xSpec style) help focus one the behavior rather than testing.

There is also a BDD group which you might find useful:

http://groups.google.com/group/behaviordrivendevelopment/

Test-Driven Development is a test-first software development methodology, which means that it requires writing test code before writing the actual code that will be tested. In Kent Beck’s words:

The style here is to write a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run.

After figuring out how to write one small piece of code, now, instead of just coding on, we want to get immediate feedback and practice "code a little, test a little, code a little, test a little." So we immediately write a test for it.

So TDD is a low-level, technical methodology that programmers use to produce clean code that works.

Behavior-Driven Development is a methodology that was created based on TDD, but evolved into a process that doesn’t concern only programmers and testers, but instead deals with the entire team and all important stakeholders, technical and non-technical. BDD started out of a few simple questions that TDD doesn’t answer well: how much tests should I write? What should I actually test—and what shouldn’t I? Which of the tests I write will be in fact important to the business or to the overall quality of the product, and which are just my over-engineering?

As you can see, such questions require collaboration between technology and business. Business stakeholders and domain experts often can tell engineers what kind of tests sound like they would be useful—but only if the tests are high-level tests that deal with important business aspects. BDD calls such business-like tests “examples,” as in “tell me an example of how this feature should behave correctly,” and reserves the word “test” for low-level, technical checks such as data validation or testing API integrations. The important part is that while tests can only be created by programmers and testers, examples can be collected and analyzed by the entire delivery team—by designers, analysts, and so on.

In a sentence, one of the best definitions of BDD I have found so far is that BDD is about “having conversations with domain experts and using examples to gain a shared understanding of the desired behavior and discover unknowns.” The discovery part is very important. As the delivery team collects more examples, they start to understand the business domain more and more and thus they reduce their uncertainty about some aspects of the product they have to deal with. As uncertainty decreases, creativity and autonomy of the delivery team increase. For instance, they can now start suggesting their own examples that the business users didn’t think were possible because of their lack of tech expertise.

Now, having conversations with the business and domain experts sounds great, but we all know how that often ends up in practice. I started my journey with tech as a programmer. As programmers, we are taught to write code—algorithms, design patterns, abstractions. Or, if you are a designer, you are taught to design—organize information and create beautiful interfaces. But when we get our entry-level jobs, our employers expect us to "deliver value to the clients." And among those clients can be, for example... a bank. But I could know next to nothing about banking—except how to efficiently decrease my account balance. So I would have to somehow translate what is expected of me into code... I would have to build a bridge between banking and my technical expertise if I want to deliver any value. BDD helps me build such a bridge on a stable foundation of fluid communication between the delivery team and the domain experts.

Learn more

If you want to read more about BDD, I wrote a book on the subject. “Writing Great Specifications” explores the art of analyzing requirements and will help you learn how to build a great BDD process and use examples as a core part of that process. The book talks about the ubiquitous language, collecting examples, and creating so-called executable specifications (automated tests) out of the examples—techniques that help BDD teams deliver great softeware on time and on budget.

If you are interested in buying “Writing Great Specifications,” you can save 39% with the promo code 39nicieja2 :)

I have experimented a little with the BDD approach and my premature conclusion is that BDD is well suited to use case implementation, but not on the underlying details. TDD still rock on that level.

BDD is also used as a communication tool. The goal is to write executable specifications which can be understood by the domain experts.

It seems to me that BDD is a broader scope. It almost implies TDD is used, that BDD is the encompasing methodology that gathers the information and requirements for using, amongh other things, TDD practices to ensure rapid feedback.

With my latest knowledge in BDD when compared to TDD, BDD focuses on specifying what will happen next, whereas TDD focuses on setting up a set of conditions and then looking at the output.

Behaviour Driven Development seems to focus more on the interaction and communication between Developers and also between Developers and testers.

The Wikipedia Article has an explanation:

Behavior-driven development

Not practicing BDD myself though.

Consider the primary benefit of TDD to be design. It should be called Test Driven Design. BDD is a subset of TDD, call it Behavior Driven Design.

Now consider a popular implementation of TDD - Unit Testing. The Units in Unit Testing are typically one bit of logic that is the smallest unit of work you can make.

When you put those Units together in a functional way to describe the desired Behavior to the machines, you need to understand the Behavior you are describing to the machine. Behavior Driven Design focuses on verifying the implementers' understanding of the Use Cases/Requirements/Whatever and verifies the implementation of each feature. BDD and TDD in general serves the important purpose of informing design and the second purpose of verifying the correctness of the implementation especially when it changes. BDD done right involves biz and dev (and qa), whereas Unit Testing (possibly incorrectly viewed as TDD rather than one type of TDD) is typically done in the dev silo.

I would add that BDD tests serve as living requirements.

BDD is largely TDD done right. However, there's additional value that BDD offers. Here's a link on that:

BDD is more than “TDD done right”

Here's the quick snapshot:

  • TDD is just the process of testing code before writing it!

  • DDD is the process of being informed about the Domain before each cycle of touching code!

  • BDD is an implementation of TDD which brings in some aspects of DDD!

Hope that helps!

Difference between test-driven development (TDD) and behavior-driven development (BDD)

  • BDD focuses on the behavioural aspect of the system rather than the
    implementation aspect of the system that TDD focuses on.

  • BDD gives a clearer understanding as to what the system should do
    from the perspective of the developer and the customer. TDD only
    gives the developer an understanding of what the system should do.

  • BDD allows both the developer and the customer to work together to on requirements analysis that is contained within the source code of the system.

There is no difference betwen TDD and BDD. except you can read your tests better, and you can use them as requirements. If you write your requirements with the same words as you write BDD tests then you can come frome your client with some of your tests defined ready to write code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top