Introduction to classic TDD

Introduction

In his book, Test-Driven Development: By Example, Kent Beck describes three strategies for unit testing:

Fake it

If your test expects a zero from a method, then return 0. Literally. It's the smallest code change we can make to turn our test green. Usually you use this when you cannot tell how to implement certain functionality, or your previous steps were too large and you cannot figure out what went wrong. Something that works is better than something that doesn’t work!

Obvious implementation

When you are pretty sure of the code you need to write, so write it and see if the test passes. The majority of the time you will use this method to move forward with TDD quickly.

Triangulation

Where you want to generalise certain behaviour but you aren't sure how to do it. Start with fake it and add additional tests that force the code to be more generic along a certain dimension.

Hands-on: FizzBuzz Kata

Last updated