Test-Driven Development (TDD) एक अभ्यास है जहाँ आप code से पहले tests लिखते हैं — एक छोटे, दोहराने वाले चक्र का पालन करते हुए: एक failing test लिखें, उसे pass करने के लिए code लिखें, फिर refactor करें। यह tests के माध्यम से design को आगे बढ़ाता है और सुनिश्चित करता है कि code testable और अच्छी तरह से परीक्षित हो।
TDD चक्र: Red, Green, Refactor
1. RED → write a FAILING test for the behavior you want (it fails — the code doesn't exist yet)
2. GREEN → write the MINIMUM code to make the test PASS (just enough, don't over-build)
3. REFACTOR → improve/clean up the code (and tests) while keeping tests GREEN
→ Repeat this short cycle for each small piece of behavior.
Write test (RED) → write code (GREEN) → clean up (REFACTOR) → repeat
