Mea culpa, mea culpa, mea maxima culpa
Jimmy Buffet, “Fruitcakes,” 1994
I hate writing tests. With the white-hot passion of a thousand suns.
Tests are good and necessary for quality software. Automating tests is the core of any CI/CD pipeline worthy of the name. I am well-versed in the value of tests and testing.
I hate writing tests.
With the white-hot passion of a thousand suns.
Yet, I sit here grateful that I wrote tests eight years ago. Or, more accurately, a lead engineer rode herd on me and every other engineer – junior and senior – to ensure that we all wrote tests. I am grateful because I was in a project meeting this week and realized that a segment of the code I wrote eight years ago met the requirements for an MVP I was scoping out. So I dig through some external drives and found the code to that old system.
The system was wide-ranging and did a whole lot more than I needed for this MVP. In fact, the vast majority of the code is irrelevant to the current project except for this one thin line that I can use for the core of the MVP. I looked at the code and was faced with the question that many developers grapple with when they are performing an archaeological dig on their old code:
“What the hell did I do here?”
Then I found those tests. Each component had its own set of tests and I was able to isolate the tests that exercised the portions of the code I needed. Out of a couple hundred code files, I was able to extract the seven that I need for the MVP. Like a donated organ, those bits of code will live on – updated and refactored – to meet a wholly different need.
So I am grateful for those tests. They were the roadmap I needed through that code. Having learned my lesson, I’ll leave this wholly unoriginal wisdom to my future self and whomever else may stumble upon this post: Always write tests.
Even if you hate writing tests.
With the white-hot passion of a thousand suns.