Getting Green on Red

The first rule of TDD requires you to first demonstrate test failure before you can write any code. In spirit, this is a simple rule to follow. If you write only just enough code to make a test to pass, another test for additional functionality should fail automatically. In practice, however, you’ll find yourself sometimes writing tests that pass right off the bat. I refer to these undesired events as premature passes.

You might experience a premature pass for one of many reasons:

  • Running the wrong tests

  • Testing the wrong code

  • Unfortunate test specification

  • Invalid assumptions about the system

  • Suboptimal test order

  • Linked production code

  • Overcoding

  • Testing for confidence

Running the Wrong Tests

The first thing to do when sitting ...

Get Modern C++ Programming with Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.