I enjoy writing tests because I love what they give me.
- I love knowing that I’m adding defense against breakage from future changes.
- I love thinking through how a feature is really supposed to work, and having the test capture that understanding.
- I love thinking about edge cases that the code should handle, and writing tests for them — especially if it turns out that the code under test didn’t yet handle them correctly, because that means I’ve just saved us from a bug.
I can remember projects with poor test coverage (which early in my career i didn’t even know was a problem) where implementing and shipping large changes was anxiety-provoking. Not only during the work, but also after deployment, holding my breath in fear of new bugs.
Conversely, I remember projects with good test coverage where similarly large changes were very comfortable to roll out. (Not to mention the bonus of feeling good from the improvements made to the test suite!)