DEV Community


Posted on • Updated on

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

Chapter 6: Equality for All, Redux

This chapter could be called VINDICATION; we are going to refactor Dollar and Franc to extend a Money superclass. This is a nice walkthrough of a mindful refactor, where we make iterative changes and keep re-running the tests.

Beck touches on the difficulty of working in a codebase that doesn't have adequate existing tests. He says to,

Write the tests you wish you had ... Retroactively test before refactoring.

This is easy to do in our Money scenario, but it's no wonder that this can go wrong; if the existing tests don't explain the proper behavior this can be confusing: how do I retrospectively know what tests I wish I had?

p.s. I messed up the commits here, having apparently forgotten to commit my changes from chapter 5. I decided to win back some honour and re-do chapters 5 and 6. In the process, I found that the natural way to duplicate the code for Franc was to copy the file in the IDE and paste it into the same folder, using the new class name. I only needed to rename the variable in the Franc.equals method.

🔎 View my code-along repo at

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.

Top comments (0)