Skip to content

Test-Driven Development (TDD) Workflow

What TDD is

TDD is a workflow:

  1. write a failing test (Red)
  2. write minimal code to pass (Green)
  3. refactor safely (Refactor)

Diagram: red-green-refactor

false


  graph LR
A[Red\nFailing test] --> B[Green\nMake it pass]
B --> C[Refactor\nImprove design]
C --> A

false

Why TDD helps

  • forces clarity on requirements
  • encourages smaller functions
  • reduces fear of refactoring

Realistic TDD

TDD is easiest for:

  • pure functions
  • business rules

Harder for:

  • UI code
  • code with many external integrations

In those cases, combine TDD with integration tests.

๐Ÿงช Try It Yourself

Exercise 1 โ€“ Write a unittest TestCase

Exercise 2 โ€“ assertRaises

Exercise 3 โ€“ setUp and tearDown

If this helped you, consider buying me a coffee โ˜•

Buy me a coffee

Was this page helpful?

Let us know how we did