The Three Stages of TDD: Red, Green, and Refactor
Learn the red-green-refactor flow of TDD.
At the heart of TDD is the red-green-refactor process—a powerful iterative cycle that guides developers in creating robust and maintainable code. In this lesson, we’ll explore the three steps of the TDD cycle: red, green, and refactor, and we’ll also learn how they contribute to the effectiveness of this development approach.
Step 1: Red (writing the test)
The first step in the TDD process is to write a failing test. This initial test describes the desired behavior of a specific feature or functionality. By writing the test before actually implementing the code, developers gain a clear understanding of the requirements and expectations.
The test is intentionally written to initially fail because there is not yet any corresponding production code. This failure is indicated by the test framework displaying a red status. The failing test serves as a tangible reminder of the work needed to fulfill the desired functionality.
Get hands-on with 1400+ tech skills courses.