TDD follows a cycle:
Write a failing test for new functionality
Write minimal code to make it pass
Refactor while keeping tests green
TDD forces you to think about requirements before coding. Tests become documentation for expected behavior.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Write tests first
TDD follows a cycle:
Write a failing test for new functionality
Write minimal code to make it pass
Refactor while keeping tests green
TDD forces you to think about requirements before coding. Tests become documentation for expected behavior.