RED, GREEN, REFACTOR

TDD has many colloquialisms and anagrams. You've already read about OOP, SOLID, and DRY. These three are all very important not only to TDD, but also to good software development practices in general. But if one saying, phrase, or mantra sums up the core beliefs of TDD, it's red, green, refactor. It reminds you of the TDD work flow of requirements flowing into tests, which then flow into code. It also sets the expectation that refactoring will occur. Developers and managers who are unfamiliar with TDD often hear the word refactor and assume it means to fix what wasn't done right the first time. This perception of what refactoring means is simply not true. Writing code is an iterative process. Refactoring is the continued refinement of your code to make it the most simple, readable, and best it can be.

The Three Phases of TDD

Red, green, refactor defines the work flow that developers follow when practicing TDD. As illustrated earlier, the sequence of steps taken in writing code is important. When followed, this order of steps (requirements, test, code) helps ensure that you have tests for the code you are writing and that you are writing only code that you have a test for.

The term gold plating refers to the addition of functionality to an application that was not requested by the user or the business but that still costs money to develop and maintain. The functionality being added may seem like a good idea. But functionality that is unneeded and unused, but ...

Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.