The Case of the Broken Unit Test
Tags: softwaredevelopment, debugging, testing
Published: 2019-08-26 13:59:22

---
title: The Case of the Broken Unit Test
published: true
tags: software-development,debugging,testing
canonical_url: https://medium.com/dealeron-dev/the-case-of-the-broken-unit-test-bbe6f0752899
cover_image: https://thepracticaldev.s3.amazonaws.com/i/aora09njn7dut6zzzcvn.jpg
---

![](https://thepracticaldev.s3.amazonaws.com/i/bgxuqpl5zu4ll02ywap1.jpg)<figcaption>Photo by <a href="https://unsplash.com/@ericmuhr">Eric Muhr</a> on <a href="https://unsplash.com">Unsplash</a></figcaption>

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 ✔️`

![](https://thepracticaldev.s3.amazonaws.com/i/1qyolf5navw37lltuh7o.gif)

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.

![](https://thepracticaldev.s3.amazonaws.com/i/smvhx0qzjtoanzwrqg9v.jpg)

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!

![](https://thepracticaldev.s3.amazonaws.com/i/x8qpfoh25ao733vpi9ga.png)

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

`All green ✔️`

![](https://thepracticaldev.s3.amazonaws.com/i/2jtof7fpgjpvtkqwd1yq.png)

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

* * *