views:

324

answers:

6

The more I read about BDD and how it is supposed to be improved TDD the more confusing it all seems to me. I've found quotes from expert that say it's about design, but also from other experts that say it's about analysis.

The way I currently see it is this:

1) analysis: BDD

from wikipedia

The result of object-oriented analysis is a description of what the system is functionally required to do, in the form of a conceptual model.

So after BDD we have the requirements (stories and the scenarios). But I'm not sure about the conceptual model part.

2) design: eg with tools like resonsibility driven design using CRC cards

3) code: coding the design, optionally use testing (like what they say about TDD done wrong, which I also find useful)

Am I wrong in how I see this? I'm having trouble seeing the forest through the trees at the moment.

+4  A: 

In short it's to do with Analysis.

BDD is for "acceptance test driven development" - i.e. for knowing if a system under test behaves as expected for a specific user story scenario.

When I worked with Jbehave we used it at the user story level and still did "conventional" TDD for handling collaborations between individual objects and between subsystems.

Typically business systems use BDD scenarios to describe business domain behaviour not to test the tiny implementtion details inside the system. You want the BDD scenarios pitched at the domain expert's level of abstraction. Those scenarios wouldn't make much sense to domain experts and would be very fragile if they described every tiny detail of the implementation.

A BDD scenario says what the system should do for a user story but not how it does it.

cartoonfox
Thanks for the answer. Seems like there is a place for TDD and BDD to coexist.
koen
@koen Sure, TDD and BDD don't have the purpose and are absolutely not mutually exclusive.
Pascal Thivent
@Pascal, maybe it would be better to use BDD and unit-testing as names. BDD as what TDD should have been if the T in TDD hadn't been misunderstood. And unit-testing as a useful practice for testing units and test they do what you want them to do at the code-level.
koen
"maybe it would be better to use BDD and unit-testing as names. BDD as what TDD should have been if the T in TDD hadn't been misunderstood." -- That's how I think about it. The only thing I would add is that BDDs are supposed to be readable by domain experts that aren't necessarily programmers.
cartoonfox
+2  A: 

BDD is about writing "executable specifications" or acceptance testing a.k.a. black-box testing which, by definition, takes an external perspective of the test object to derive test cases.

So BDD can't be about design, BDD is about testing features/stories/scenarii, BDD is closer to analysis.

Pascal Thivent
The "executable specifications" writing makes a lot of sense.
koen
+1  A: 

I think from an architecture POV BDD would be about design. I need to design an application that can do something, that will later be used in acceptance testing. So, from the high-level design I want to make certain that I am designing for the various behavior requirements, so that I am not overdesigning, and limit duplication.

It helps with ensuring that we may not need to redesign as the user has has more time to think about what they actually want to see, how the application will perform.

James Black
I see where BDD has a relationship to the design when you say that the design must conform to the behavior requirements. But isn't BDD about getting to know what those requirements are and formulating them in a common language? Then the design must conform (e.i. make work) the requirements and BDD is about analysis. Currently I'm more inclined to accept what the others have answered.
koen
@koen - It depends on at what level you are doing the design. If you are designing from a high-level then BDD helps to ensure that all the requirements are met, then there is more design to continue to designed down to tasks or features, so it can be implemented.
James Black
+1  A: 

BDD (or TDD for that matter) isn't about anything. It's a technique (in the case of BDD, more of an approach) that supports analysis and design (as well as that pesky little implementation step). You often hear the phrase "red, green, refactor" associated with TDD, and so it applies to BDD: create the test and see that it fails, make the test pass by updating the codebase, then rework the system into an improved form while you preserve the passing tests.

So BDD supports analysis when you create the tests: you should be describing the behaviour required in the form of tests or examples. It supports design when you run the tests: your design decisions are prevented from inadvertently breaking required behaviour, and can be guided by the analysis. But it doesn't do any of the analysis or design for you; you still have to think. It's a way of making sure that, during the analysis and design steps, you don't contradict yourself.

Zac Thompson
Thanks for adding another viewpoint to this.
koen
+1  A: 

BDD - Behaviour Driven Development

Behavior = ..in the context of.. Development - ...in the construction of...

Development in this case indicates to me that the analysis has been done and one is implementing something that is in the context of a specific behaviour.

so to answer the question, I beleive its in the Design.

Mark Redman
For some development includes analysis and design, others think it starts when analysis and/or design are done. The 'what is in a name' approach to finding my question out is something I haven't considered yet, especially concerning the meaning of development. It would be nice to hear what the BDD originators think development is.
koen
+1  A: 

BDD and TDD even more have a very unlucky name because it doesn't actually cover what they are used for.

  • You don't want to write tests for every possible corner case during your dev cycle that is something testers should pick up.
  • You don't want regressions and you want to be sure you're writing the code you need to clear this iteration so you want a repeatable result
  • You don't have to do detailed designs at the start but rather jot some requirements down you want to see finished this time around.

BDD/TDD any of the 2 is fine if you don't write a line of code before you have a bit of code that describes the bit of code you're about to write. Doing that you'll get into a zone.
While there is no proof that BDD/TDD will improve your dev speed (most likely won't) it will greatly reduce the number of issues you get back after releasing the software which has been proven.

BDD is an evolution of TDD where TDD puts the pressure on to test everything BDD relaxes this and says that you should only test the public behavior of your classes because the internals are likely to change.

BDD is as much about design as it is about analysis, but I don't think that that is your question is it? You want to know how to translate the stories into flowcharts and architectural diagrams?

Because from what I get from your question is that you make a big design up front and then try to code that out. That won't work with BDD because whilst satisfying your stories which you should write in a piecemeal fashion your get your code and architecture automatically. It's called emergent design so there is no huge planning phase.

In a SCRUM or like wise system this works really well because the business prioritizes your stories. You start from the top and write a spec/example for it then try to satisfy the example repeating this until you've completed this backlog item and then pick up the next one and start over again.

I hope this answers your question.. if not you'll need to clarify a little because it's a braod topic. In short BDD is purely a developer tool, not for architects, BA's,... Testers may use the BDD tools but I hope that isn't the only tool they're using to test the application.

Casual Jim
Thanks for your answer Jim. I understand that I'm supposed to start from (a few) stories and let the design emerge. What I don't get is how it would deal with adding stories that would change the design almost completely.
koen
You generally start an application with a big picture of what it's going to do. As a consequence of using TDD/BDD successfully your objects should be very much loosely coupled so in general it's a question of implementing a new class with the new functionality.The important thing is to design for change so that you can replace the individual bits and pieces but not affect your overall design. Do you have a concrete example of a change that affects design that deeply?
Casual Jim
Yes but I think it's too technical to lay out here. Maybe I should finally buy 'TDD by example' or so :-)
koen