loading...
Cover image for The Case of the Broken Unit Test
DealerOn Dev

The Case of the Broken Unit Test

jackdo profile image Jack-DO Originally published at Medium on ・3 min read

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

@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.

Fin


Posted on by:

DealerOn Dev

On the DealerOn Development Team, we strive to be the industry leader in code quality, innovation, and culture. The author’s views expressed in this publication are endorsed by DealerOn. The author’s views elsewhere are their own.

Discussion

markdown guide