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 https://github.com/ruthmoog/test-driven-development-by-example
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)