← Writing

"My Friend, Why Do You Code So Sloppily?" — How I Learned to Love Unit Testing

There was a season of my career where I genuinely thought unit testing was the bane of my existence. Now I can’t imagine working without it. Let me tell you how that flip happened.

In one of my previous projects, testing wasn’t a “nice to have.” It was law. We had SonarQube watching over us like a hawk — code coverage had to hit the mark, no exceptions. And it wasn’t just “write a quick test and move on.” You had to cover the happy path. Then the edge cases. Then the weird, annoying, will-this-ever-actually-happen cases. All of it. Every single time.

It was such a hassle. I won’t pretend otherwise. There were days I just wanted to ship the feature and be done, and instead I was sitting there writing my third test for a function that clearly worked fine, thank you very much.

And then there was my lead. Bless his heart. That man was always — always — the first to look at my work and go, “My friend, why do you code so sloppily? You code it like this…” and then proceed to actually teach me. Every. Single. Time. I’m not going to lie to you, in the moment it was one of the most annoying things ever. Tsk. You think you’ve done something good and there he is, gently dismantling it in front of you.

But here’s the part that took me embarrassingly long to appreciate.

When you stepped back and looked at the bigger picture, our team had almost zero issues when we deployed to production. Zero. In an industry where “it works on my machine” is basically a meme, we were shipping clean, over and over again.

And why was that? Two reasons, really. First, my lead — for refusing to let me get away with sloppy work. And second, the tests. Those annoying, repetitive, hassle-of-a-thing unit tests. They weren’t busywork. They were guards. Quiet little sentinels making sure the code never dropped below a certain standard before it ever got near a user.

That lesson rewired how I think about building software. The “annoying” discipline was the whole reason we could sleep at night after a release.

To this day, TDD is one of the first things I reach for, not the last. Write the test, then write the code that earns it. It still feels like extra work up front — and it still saves you ten times that pain down the line.

So if you’ve got a lead right now picking apart your code and it’s driving you up the wall: hang in there. That friction might be the best thing happening to your career. Mine was.

Thank you, by the way. You know who you are.