My feeds caught up with me and I found myself reading a few articles about BDD—Behaviour Driven Development. In essence, this is nothing new, just a new perspective, and terminology, for TDD—Test Driven Development. But things are more real when you say them out loud.
BDD is a developer’s coming of age with respect to TDD. I’ll restate, in my own words, the BDD levels of enlightenment you should achieve:
You write tests
- to check that your code works
- to ensure that changes don’t break anything
- to clarify what you don’t need
- to document how to use the code
- to clarify what you need
It’s hard to explain the value of writing tests to people who don’t. Hell, it’s hard to keep believing even when you have experienced it firsthand.
One thing that I keep going back to is “wishful thinking.” They talked about wishful thinking in SICP as a design methodology. Instead of “going away” and writing some potentially complicated piece of code, just assume it exists and start using it. Then, after your “client” code is completed, fill in the blanks. Remember that you can recursively apply this process while you are filling the blanks. I believe that this is exactly what point #5 above is all about.
Still in the BDD vein, I found RSpec. RSpec turns your tests into the spec. This makes a lot of sense when you think that good tests should be based on the spec. I followed the tutorial, but I recommend you skip to the last page to get an idea of what your test suite could be like.
Like all good ideas, BDD seems obvious in retrospective.