Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is BDD a replacement of TDD?

I wonder whether BDD is a replacement of TDD? What I understand now is that in an ultimate BDD we don't have unit tests any more. Instead there are stories/scenarios/features and "test steps". And it looks like a complete replacement of TDD for me. TDD is dead?

like image 579
yegor256 Avatar asked Oct 11 '10 09:10

yegor256


People also ask

Is BDD an extension of TDD?

Behavior-Driven Development (BDD) – An extension of Test-Driven Development (TDD) Behavior-Driven Development (BDD) is a process or best practice for the development (and testing) of code.

Is Cucumber BDD or TDD?

Cucumber is an automation tool used for automating acceptance tests that are written in BDD(Behaviour driven development) style, in the form of features. In cucumber we have two types of files – a feature file and a step definition file.

Can you tell me the difference between BDD and TDD?

Behavior Driven Development is a development technique which focuses more on a software application's behavior. Test Driven Development is a development technique which focuses more on the implementation of a feature of a software application/product.

Can you do TDD and BDD?

They can ensure that units work as expected in isolation. That's why you should use both TDD and BDD. Each approach caters to a different need. While BDD is a higher-level, user-centric approach focused on encouraging conversation and collaboration, TDD is a development technique.


3 Answers

Gabriel is almost right.

The fundamental difference at a unit level is that BDD uses the word "should" instead of "test". It turns out that when you say "test", most people start thinking about what their code does, and how they can test it. With BDD, we consider - and question - what our code should do. It's a subtle but important point, and if you want to know why that's powerful, go read up on Neuro-linguistic Programming - particularly around the way in which words affect thoughts and the model of the world. As a brief example, many people who are new to TDD start pinning their code down so that nobody can break it. BDDers tend to provide examples which demonstrate the value of their code so that people can change their code safely.

Dan realised while he was talking with Chris Matts and writing JBehave that he could take this up to a scenario level (scenarios aren't quite the same as stories). Because we were already using "should" at a unit level, it made sense to start writing things in English (I tend to use "should give me" rather than "should return", for instance). Acceptance Test Driven Development - ATDD - has been around for a long time, but this was AFAIK the first time anyone had written them in English with business stakeholders involved.

It's more than just a replacement for TDD. It's a different way of thinking about testing - very much focused on learning, deliberately discovering areas where we perhaps thought we knew what we were doing but didn't, uncovering and helping us to resolve ignorance and misunderstanding. It works at many levels. Chris Matts' Feature Injection takes this into the higher level space, right the way up to project visioning.

We still do write examples - or specifications if you like - at a unit level too, but really, it's a pattern which goes far higher than even scenarios. If you want to know more you might find my blog useful, Dan's is even better. Also, Chris has a comic book on Real Options which outlines some of the patterns I've mentioned.

like image 180
Lunivore Avatar answered Feb 07 '23 00:02

Lunivore


Not at all. BDD is just a variant of TDD.

In TDD, you formulate your requirements as an executable test, then write the production code to fulfill the test. BDD does nothing but re-formulate these requirements into a more human-readable form and thus makes the tests somewhat more verbose to a human reader who looks at the test report. (Btw: To achieve this, BDD requires way more code than traditional data-driven unit testing...)

That's all.

Thomas

like image 35
Thomas Weller Avatar answered Feb 07 '23 02:02

Thomas Weller


I have a different viewpoint on this than other responders.

Dan North created BDD druing his consulting work on TDD when he saw, that many people were confused by the "test" part, because they had testing experience, he decided to change the name. So at first, BDD was exactly what TDD is, explained correctly. After that Dan started to extend the idea of using executable specifications (unit tests) to drive the implementations by adding another levels of specification. He was inspired by user stories, so the simplest BDD implemented by most tools lets you write requirements as user story scenarios, than you write code which generates unit tests and than from those unit tests you work on implementation. So now you see compared to TDD there is another level of specification - user stories. Many tools include prepared translations of user stories to tests, so many forget about them as you did, but they are still there and cannot be fully omitted - practically and also theoretically as noted, programming user stories is not efficient. But that is not the point, you use user stories to gather requirements from stakeholders and to proove you implemented them by executing acceptance tests.

There are many other small things in BDD, you better read Dans blog to understand them, but the main point is that BDD is an extension of TDD even outside the implementation phase, so they cannot be interchanged or rendered useless by each other.

like image 36
Gabriel Ščerbák Avatar answered Feb 07 '23 00:02

Gabriel Ščerbák