Use Zombies in TDD
Test-driven development is a powerful development technique for building reliable software. You can incorporate it into your development workflow using the ZOMBIE approach. This method focuses on iterative progress, making sure your tests gradually increase in sophistication while maintaining control over the code’s logic and exploring testing paths in a methodic order.
The ZOMBIE methodology advises you to start with tests for Zero, One, and Many cases to verify your implementation. Using zombies in TDD helps you focus on building functionality incrementally while preventing premature complexity. The principle is simple: start with the simplest possible solution (even a hardcoded one), then evolve it into a more robust design over time.
The TDD ZOMBIE Cycle
To illustrate how the ZOMBIE cycle guides you in writing tests, we will build a classic Tic-tac-toe game in JavaScript using the ZOMBIE acronym:
- Zero
-
Start by writing tests that handle cases when the input or game state is zero or empty.
- One
-
Write tests that check how the system behaves when there is only one move or the smallest piece of data.
- Many
-
Gradually introduce multiple moves or more complex scenarios to test.
- Boundaries
-
Ensure that edge cases, like an already taken square, are handled.
- Interfaces
-
Test public interfaces like methods and game APIs.
- Exceptions
-
Finally, check how the game handles invalid inputs and exceptional ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access