Test example 7 – how to refactor your code
From a TDD perspective, the previous six test examples fully neglected a very essential part: the refactoring of the code, or more accurately, one of the two rules that make TDD: Rule 2 Eliminate duplication.
As I hope you will experience here, refactoring is not rocket science but a discipline, as I tend to call it. Refactoring is not a goal on its own, but a means to exercise this second rule of TDD, with the valuable resulting effects of getting reusable, readable, and minimalistic code.
Contrary to what many of us have been taught when becoming a developer, though, with TDD we do not design reusable, readable, and minimalistic code upfront. No, when performed with common coding sense, rule 2 leads you there. As you might recall from Chapter 2, Test Automation and Test-Driven Development, with TDD your first gear is taking small steps to be effective and efficient. Meaning that you don't do more than required for that...