Test-Driven Bug Fixes

Bug fixes need tests too. The existence of a bug often shows where prior test efforts have failed. If we can write a unit test to reveal the bug, do so. If investigation is needed to track down the bug, do the investigation and capture some of your knowledge in the tests as you go. Once the bug has been located, write a unit test that reveals the bug. Resist the temptation to immediately fix the bug.

You want to make sure you don’t give life to new bugs when you kill the bug you were hunting. Also, bugs have been known to nest together. Both of these realities mean you should also write tests to lock in the desired behavior before fixing a bug.

As you noticed in crash to pass, the first test in a new area usually ...

Get Test Driven Development for Embedded C 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.