DEV Community

Cover image for The Case of the Broken Unit Test
Jack-DO for DealerOn Dev

Posted on • Originally published at Medium on

The Case of the Broken Unit Test

Photo by Eric Muhr on Unsplash

One seemingly fine day, I made the mistake of running unit tests locally. There I was minding my own business, having just finished working a ticket on my team’s main project, I decide to be diligent and ensure all tests ran properly. That’s when everything went horribly wrong. “ 1 failed ❌” the Test Explorer exclaimed. Anxiety rising in my throat, panic racing up my back, I started to debug the failing test.

Expected result: -1

Actual result: @1

@1… AT ONE?!?! There’s no such thing as @1, this is an integer. Fearing the worse I checked out our development branch fresh to ensure I wasn’t the one who had killed the build. Much to my horror I watched the same massacre unfold.

1 failed ❌

It turns out I was not the killer.

Opening a ticket, I sent an alert to my stalwart team members.

“The development branch is broken, unit tests are failing, no I’m not joking this is serious business!

“What are you talking about?” I hear come over the wall. It’s my team’s Technical Lead. “All tests are passing for me.”

There, on his screen, right before my own eyes is our precious baby soaring through those units.

All green ✔️

I get my partner to do the same.

All green ✔️

OK, now I know its me. Let’s go to the source. The value being faked out by the test is stored in the database in the wild, so I check there.


@1?!? This is an int column!

I get my partner to query the db: -1

The plot thickens. Am I losing my mind? These values aren’t possible and most certainly shouldn’t change based on who views the value in the data store.

My dear Watson, what could cause a minus to become an @? Surely there is a logical explanation for this. Wracking my brain the first thing that comes to mind is CultureInfo.CurrentCulture. Eureka! It suddenly comes to me like an electric shock. My culture settings! After discovering how, I open my culture settings. There was the culprit. In the formatting, the negative symbol was set to a an @ sign. This explains everything!

I correct the setting and check the database: -1. My confidence returning, my nerves steadying, I rerun the failing tests.

All green ✔️

Jubilation! My Kafkaesque nightmare is over. The existential crisis comes to an end yet again. I do, in fact, know what I’m doing. I haven’t simply stumbled this far through a comedy of errors and found myself dumbfounded in the day to day of my trade. I inform my team members who were involved in helping and anyone else in earshot I think would find it interesting. “You should write a blog post about that” my Department Lead responded on hearing my tale. And that my friend is why you find yourself here.


Top comments (0)