Case for Unit Testing


I have had a rollercoaster ride when it comes to unit testing.

Early in my career, it felt overwhelming. I was just trying to learn basic fundamentals and testing added a lot of complexity I just wasn’t able to grasp yet.

Fast forward a few projects without it and I knew it was time to wrestle the topic. It takes a lot of work! For one, I was doing it on side projects and not at my full-time, 40-hours-a-week job. Second, when you are focussed on the discipline of TDD, you don’t have room in your brain for a lot of test design thinking, therefore my test API was hot garbage at first.

Just like anything, it took some failing and doing before I saw the light. Once I had a grasp on how to test, not just from pure TDD mechanics, but also from a design standpoint, I saw the light and couldn’t go back.

It also helped all of my work conformed around Node.js, and the Javascript community is ridiculously into testing. Tools like Jest and Wallaby.js make the red/green/refactor process painless.

With all of that said, selling myself on TDD was only half of the battle. I am always working in a team, and I always get one of these responses:

  • Tests take too long to write/we don’t want to write them
  • How do we get started with legacy code/a legacy project?

How to get started in a legacy project is a simpler problem to solve because the team is somewhat convinced to at least start writing tests.

However, Facebook just released some pretty good ammo to use on teams that just don’t see the value and don’t want to get started.

Facebook completely re-wrote React.js, their popular and open source front end framework.

For those that haven’t seen it, there is a popular blog post about why you should never re-write your software.

How and why did Facebook do this?

Why might be a different story, but the how is fascinating to me.

First thing they did? Made a website that tracked how many unit tests were currently passing, when then drove the entire re-write.

They then (A/B) tested against and Messenger, which is also an interesting read.

Next time I need a case for unit tests, this will probably be one of the first places I turn: