Have unit tests ever saved you?

October 14, 2022
Three times unit tests saved me, in as many days.

I saw a poll on social media recently asking this question.

Have unit tests ever saved you?

I replied in a comment: Daily.

Here are three times unit tests have saved me, in as many days.

Today

I was writing a test for a small library I had written, that queried a third-party API. The test I was writing revealed that I had made a mistake, and had assigned the City value from the API to both the City and PostalCode fields of the response.

Yesterday

I made some changes to a logging library used by a number of microservices. The tests I had previously written started failing, alerting me to an incompatibility I had introduced, which would have been very painful to discover in production.

Day before yesterday

Writing a client library for another third-party API, my tests revealed that I was returning conflicting date formats. Turns out this one was a but in the third-party API. If I hadn’t writen tests, I wouldn’t have noticed until later, when the date parsing started crashing in production.

Share this

Related Content

I just threw away a bunch of tests

I had failed to complete the "refactor" part of "red/green/refactor" several weeks ago, leaving me with some redundant tests that came back to bite me.

Reader response: The downward spiral of manual acceptance testing

Lack of unit testing drives the need for manual testing. Since testing is bunched up, development is as well.

Why continuous deployment is better for emergencies

Multi-stage software delivery means no hotfixes, or lots of extra work.