BDD – TDD done well?
Someone on the XP thread suggested, “BDD is just TDD done well with different words.”
Here’s my take.
An application is the end-product, and the value of the application is delivered through its behaviour, as perceived through its user interface.
BDD uses descriptions of behaviour and executable examples (or exemplars; examples carefully chosen to illustrate a particular behaviour). These exemplars, whether in code or plain English, are an aid to communication, to driving a clean, simple design, to understanding the domain, to focusing on and delivering the business value, and to giving everyone involved clarity and confidence that the value is being delivered.
Is doing the above merely ‘doing TDD well’? Maybe it is, but I think that the words do help to change the focus; also, my experience (amongst others) is that some people who struggle to do TDD well find BDD relatively easy.
Here are some of the practices I use in BDD.
A story is a narrative from a customer in a particular role, describing a particular feature and a value that will be delivered through the use of that feature. Scenarios associated with the story will be executable, either manually or through automation, once the feature delivers the value.
(This isn’t a practice; it’s just how stories and scenarios work.)
Making the scenarios and examples executable allows us to know when the value has been delivered, at each level of code. Maintaining those examples allows us to continue to have that certainty as other features are developed.
(This isn’t a practice; it’s just how good tests work. But without using the word ‘test’.)
Each level of code in the application delivers value to some other piece of code, through its own behaviour and its own interface (which could just be the externally visible methods, or an actual java-style Interface). Eventually the sum of those values is delivered to the user interface, which delivers the value to the customer.
(This isn’t a practice; it’s just how software works.)
Describing these stories and behaviours in English allows more people to understand the code and talk about it than otherwise might. For developers, it encourages the use of English in place of Geek. This aids communication.
Driving behaviour from the user interface downwards, and focusing on each unit of code, its responsibility to deliver its value to another, and its ability to use other code to deliver value to itself, minimises non-valuable code and allows developers to split responsibilities easily. This results in a clean, simple design.
Capturing common contexts, events and outcomes, and using these as part of the (coded) domain language, helps us to understand the domain.
Coding the story and scenarios (exemplars at the user interface level, automated at the closest possible level to that interface) helps us focus on, and deliver, the desired value.
Using English for executable scenarios and examples means that everyone, including the customer, can understand which values are delivered, which have been lost (either deliberately or otherwise), and which are yet to come. This helps to give everyone clarity and confidence.
(These are some things I practice as part of BDD.)
I believe this is more than just ‘doing TDD well’. I think it’s ‘doing TDD and a number of other practices related to professional software development well’. The five practices above might conceivably be done in addition to TDD, but they’re not part of any definition of TDD I’ve seen.
Agile house building
Next time you hear someone compare software engineering to building a house, point them at this:
http://www.touregypt.net/featurestories/snefrubentp.htm
“The Bent Pyramid, though largely intact, owes its preservation to the builder’s realization of their errors soon enough to make changes to their initial building plans.”
Even the ancients didn’t get it right first time.
Imagine a future in which all buildings are constructed from component modules. These modules can be easily adapted to fit one another. Walls, doors, windows, stairs and structural elements can be moved from one module to another, and are easily repainted to match your colour scheme. Each module also has a bar which flashes red when they’re in danger of structurally failing, either due to the stresses of the building* or of human habitation.
Halfway through the building process, you realise that there’s room for a swimming pool in the lounge. Your friend has one and it’s great for parties. So you change the design. The builders are quite happy to slap it together for you, content in the knowledge that the red bar keeps things safe.
After two years, you find you need an extra bedroom. It’s quite easy to extend the lounge and bolt the bedroom on top. You need to move another room to create room for the extra door, but that’s easy too. While you’re there, you move the swimming pool to the roof.
A year later, you are able to work from home, so you port your entire house to the wilds of Scotland, where you have a great view of the sea.
Why would you not want to build a house that way?
*I love checkstyle
Your horoscope for June
How people
Just when you thought you had a handle on how things worked, someone changed it again. Even coffee tastes of the ashes of your defeat. Keep smiling; it’s nothing that can’t be solved with some fava beans and a nice bottle of chianti.
Your tool of the month is Console 2.00.
Why people
A problem shared isn’t a problem solved, but ask around; you may find unexpected allies on your side. Listen to their advice. They have no idea what they’re talking about, but it’ll work anyway.
Your word of the month is etymology.
Who people
Midsummer brings the usual round of parties, mayhem and magic. There’s nothing like a practical joke between friends, but this time the joke is on you. Be careful , or you could end up looking like a bit of an ass.
Your pub of the month is the Coach and Horses in Farringdon.
When people
It’s been a difficult month, but collaboration and shared ownership finally paid off. Who’d have thought it? It’s time to give in to those generous urges and reward all that hard work. After all, you deserve it.
Your quote of the month is: Quotation is a serviceable substitute for wit.
–

Comments