Have unit tests ever saved you?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.
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.
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.
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.
Improve your software delivery