Skip to content

Todo list TDD tutorial

Greg Bowler edited this page May 9, 2026 · 2 revisions
  • Doing the todo list tutorial again, but this time tests are written first.
  • The implementation will be skipped over, because it's already shown in the original tutorial.

Getting started with TDD

  • Good rule: do not write any code until there's a failing test ready for it.
  • Then, write the smallest amount of code possible to satisfy the test.
  • Then repeat - trying to cover all edge cases.
  • When complete, the software will be bulletproof, new features will be easy to add without regressing functionality.

First steps

  • No need to test that a TodoItem class can be constructed, or that its properties are the correct value - that's pointless.
  • First test: the todo list should be empty by default - easy to test.
  • Next: requesting a todo item by ID should be null.
  • Next: after creating a todo item, it should be in the todo list.
  • Next: after creating a todo item, it should be retrievable. Then it should be editable, and the next retrieved todo item should have the changed content.
  • Next: toggle complete status.
  • Next: delete items.
  • Next: entire functionality complete, but this time functionality is provable.

Behavioural tests

  • Introduce Behat browser testing.

Move on to the next tutorial: [[address book tutorial]].

Clone this wiki locally