Do You Code Review Your Tests 🎢

Apr 08, 2022 2:01 pm

Happy Friday,

A big thanks to those of you who emailed me with encouragement and shared my excitement about bees! They're happy and healthy. I was freaking out the first time, being the proud dad of ~20,000 new kids can do that.

Especially since it snowed the day after I got them.

Anyway, they're alive and well and if you want to see a video of the ladies from Wednesday when I did my big check, you can watch that here.

It shouldn't be any surprise that I love the unlovable parts of our software industry, which means I love tests. I was on a call with a client who admitted that they got completely lost when looking at their tests because they knew there had to be a better way, but they couldn't decide what to do.

This led me to a question.

"Do you code review your tests?"

The answer was they do not. This is common for a lot of groups I see. They are adamant about checking on the production code, but the tests are often ignored.

But lets do a thought experiment. If we do code reviews to protect ourselves from buggy poorly written code, and tests are code, then shouldn't we review that too?

After all, if the tests have bugs and are poorly written, won't that create problems down the road?

Of course it will.

Ignoring test quality often leads to a few symptoms.

  • Long execution
  • False positives
  • Misleading names and messages
  • Shadow implementations

So my advice is to incorporate the test code into your code review. Now, test code is a different animal from normal code, so it will be slow at first because what we look for tends to be different. Here are some things to look at when you're reviewing test code.

  • Number of assertions (With a preference for a single assertion)
  • Assertion of a real value
  • Good names for the tests
  • Independence with good setup/teardowns
  • Execution speed
  • Can the contract test be combined (Contradicts the first one, but it happens!)
  • Does the test have an execution order (This is bad)
  • Out of control mocking
  • Unmanaged test data

There's more to consider, but by reviewing tests we keep the very thing that protects us in good working order.

I'm curious though, how many of your groups look at the test code as a part of code review?