Here’s an interesting mental exercise that recently I’ve found more and more valuable:
- Test drive your code (duh).
- Before each time you run your tests, no matter how small the changes you’ve made, ask yourself why the tests will fail. Don’t just gloss over this; be explicit. Say it out loud or write it down, if that helps. If you have a pair, tell your pair.
You might be surprised how often your assumptions turn out wrong. And, you might be surprised what you learn when you explicitly state those assumptions and then have to justify them when they do turn out wrong.
If you don’t test drive, or you don’t always test drive, (and you’re still reading), ask yourself this: what happens those times when my assumptions are wrong and I don’t have tests to protect me?