Published on

Are unit tests a waste of time?

Authors

TL;DR They are not, skip them and suffer. There's never going to be a "we write them later" and development will slow exponentially as the project grows.

An engineering manager I've once worked with downright banned unit testing in our team to save time. It was a startup and the project was greenfield. He manually tested the app itself and saw no reason to hinder development since things were going smoothly. A year and a half later, before I left the company, there were very few changes that required less than a full day to complete and test. There were plenty that took weeks.

Subscribe and get articles like this in your email!

Don't make the same mistake. Unit tests are part of the definition of completion, they breed good architecture and allow for faster iterations. A program is simply not done if it's not tested. Consider this:

  • Debugging process Remember when you had that one awkward bug, and it took days only to reliably reproduce it? Unit tests allow you to control the state of your components in great detail, making it easier to find and fix such issues.
  • Reusability and life span If you wrapped up some code in a reusable library, chances are you'll improve it frequently. Unit tests can help you ensure no breaking changes sneak through each iteration.
  • Complexity When you can't reason about a system as a whole, it helps to frame it in isolation.
  • Third-party dependencies Software requires the perfect alignment of many moving parts, some of them not under your control. When third parties act unexpectedly, it becomes almost impossible to debug your system. Mocking dependencies in your unit tests solves this.
  • Costs If you think you don't have a budget to unit test, you certainly don't have one to skip them.
  • Team size You'll find that as you make your code testable, you also increase its intrinsic quality. Also, unit tests are the closest thing to written specs, and while you can manage without any formal requirements while working on a part-time project by yourself, larger, heterogeneous teams would have a hard time doing so.