TDD
WORKSHOP

80 minutes · 3-Way Ping-Pong · Hands-on Practice

The TDD Rhythm

1
Red
Write failing test
2
Green
Make it pass
3
Refactor
Clean up code
Repeat
Next test
80

Today's Schedule

0:00

Welcome & Setup

5 minutes · Verify environment

0:05

Live Demo: FizzBuzz

15 minutes · Watch TDD in action

0:20

Exercise Intro

5 minutes · 3-Way Ping-Pong explained

0:25

Hands-on Practice

40 minutes · Mob programming

1:05

Retrospective

15 minutes · Reflect & discuss

3-Way Ping-Pong

A
Red
Uncomment test
Watch it fail
B
Green
Write minimal code
Make it pass
C
Refactor
Clean up
Next test

Rotate roles with each cycle · One shared screen

RED Phase

Write a failing test

  • Uncomment ONE test
  • Run dart test
  • Watch it fail (proves it can fail)
  • Pass the keyboard
// Uncomment this test
test('returns 1 for input 1', () {
  expect(fizzbuzz(1), '1');
});

GREEN Phase

Make it pass (minimal code)

  • Write the simplest code that works
  • Don't worry about perfection
  • Run tests to confirm GREEN
  • Pass the keyboard
String fizzbuzz(int n) {
  return '1'; // Hardcode is OK!
}

REFACTOR Phase

Clean up the code

  • Remove duplication
  • Improve names
  • Tests stay GREEN
  • Uncomment next test (back to RED)
  • Pass the keyboard

Choose Your Kata

Password Validator

Rules-based validation · Refactoring challenge · Open-Closed Principle

Shopping Cart

Stateful domain object · Data structures · Value Objects

TDD Principles

  • Tests first — Even for "obvious" code
  • Small steps — One test at a time
  • See RED — Proves the test can fail
  • Minimal GREEN — Hardcoding is OK initially
  • Refactor fearlessly — Tests protect you

Ready to
Practice?

Let's build muscle memory for TDD

1 / 10