Writing Tests First
Practice writing failing tests that define desired behavior before implementing any production code.
TDD's 'Red' Phase
Welcome to the core of Test-Driven Development (TDD)! In this lesson, we'll dive into the crucial first step: writing a failing test first.
This is often called the 'Red' phase of the TDD cycle, because when you run your tests, you expect to see a 'red bar' indicating a failure.
Why Test First?
It might feel counter-intuitive to write a test for code that doesn't exist yet, or isn't fully implemented. But this approach offers great benefits:
- Clarity: It forces you to think about what the code should *do* before you think about *how* to do it.
- Proof of Failure: It proves your test works correctly by showing it can fail. If it passes without any code, your test might be faulty!
- Focus: It gives you a clear, immediate goal: make this one test pass.
All lessons in this course
- Introduction to TDD Cycle
- Writing Tests First
- Refactoring for Testability
- The Three Laws of TDD