Loïc Faugeron Technical Blog

spec BDD 05/03/2014

TL;DR: jump to the conclusion.

This article is part of a series on Tests in general and on how to practice them:

  1. Introduction
  2. Tools overview
  3. Test Driven Development
  4. TDD: just do it!
  5. spec BDD
  6. phpspec: a quick tour
  7. Behavior Driven Development: story BDD
  8. Behat: a quick tour
  9. Conclusion

In this article, we'll talk about Behavior Driven Development (BDD). There's no special skills required to read on, although some notions on although some notions on tests and Test Driven Development (TDD) would be a plus.

From TDD to BDD

Dan North, a fervent TDDist, felt that there was something missing about this practice:

While being an adapt of the concept, he felt that there was missing some important guidelines, and that his tests didn't answered the right questions.

Around 2006, he wrote an article called introducing BDD, in which he explained his unease and how to fix it: instead of writing tests from a technical point of view he decided to write them from a business point of view.

From unit tests to specification

The first step to test the behavior of a class is to write a specification. Because xUnit frameworks were in vogue, developers had the habit of making a parallel between their Systems Under Test (SUT) and their Test Suites:

In the Software world, a lot of problems can be solved by giving descriptive names. And this is what Dan North did: Test Suites became Specification. Why? Because it forces you to say "this method should do this" instead of writting "test method".

To be more precise, Dan Nort stated that "test method names should be sentences". Which means that test method names should be snake_cased, as underscores give more spaces to words (they're basically spaces).

And that's pretty much it!

Is that all?

Yes! Well, no. I mean... This is only the first part of BDD: it's called specBDD (guess why ;) ). I'll write about the second part (story BDD) in a future article.

Conclusion

BDD is just TDD, but tests become specifications and test methods are sentences which start with "it_should".

I hope you enjoyed this article. If you want to make any comment, you're welcome to do so on Twitter.

To keep good habits, in the next article we'll switch to the technical mode and see some phpspec!