Test Driven Development

The Red-Green-Refactor cycle is a fundamental process in Test-Driven Development (TDD) consisting of three steps:

Red:

  • Write a test for the next bit of functionality you want to add.
  • Run the test and watch it fail. This step ensures that the test is valid and the functionality doesn’t exist yet.

Green:

  • Write the minimum amount of code necessary to make the test pass.
  • Focus on getting the test to pass, not on perfecting the code.
  • Run the test and see it pass.

Refactor:

  • Refactor the code to improve its structure and readability without changing its behaviour.
  • Ensure the code is clean and maintainable while keeping all tests passing.
  • Run all tests to confirm that the refactored code still passes.

This cycle encourages incremental development, ensuring that each new feature is properly tested and integrated into the codebase.