Book Club: "Test Driven Development: By Example" #1

ruthmoog - Mar 28 '22 - - Dev Community

Book cover Kent Beck's "Test Driven Development: By Example" was released in 2002. The book aims to explain how to use TDD to write quality code that works.


Chapter 1: Multi-Currency Money

Beck starts by introducing a To Do list of the behaviour needed to solve the problem. I've found doing this helpful for two reasons; it helps to stay focused on just the list item; you can't do this step if you don't know enough about the problem - and it's helpful to find this out before you start writing any code.

Once you have a list, and have selected which item to start with, you start writing a test. I have learned quite a bit about TDD in theory, but in practise writing tests is hard. Beck's examples use very small incremental steps,

TDD is not about taking teeny-tiny steps, it's about being able to take teeny-tiny steps.

This can be hard in an existing codebase, where there may already be test helpers doing multiple steps and, working in an unfamiliar area or domain can make this harder too. I usually start by writing a given, when, then statement in plain english and attempting to build it up bit-by-bit with working code.

Having a test that fails as you write each part of it shows you that you're developing the code as you write your test. Race to green with code that works (you can make it lovely later when you refactor). If you discover problems along the way add them to your To Do list.


🔎 View my code-along repo at https://github.com/ruthmoog/test-driven-development-by-example

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player