Ognjen Regoje bio photo

Ognjen Regoje

I make things that run on the web (mostly).
More /ABOUT me.

me@ognjen.io Twitter LinkedIn Github

The most important benefit of test-driven development: coverage

Test-driven development and it’s pros and cons have been extensively written about.

Most common pros are often said to be having to think or plan your code out before writing, that it increases productivity and reduces bugs.

While those things themselves are quite important and useful I think the most important benefit is often overlooked.

TDD forces you to have correct and thorough test coverage.

I think this is more important than all of the above.

You don’t need TDD to plan your code well, or to be productive or correct.

But, TDD makes comprehensive coverage almost a side-effect.

Especially once things get tough and quality starts to suffer, if the team is not following TDD, it’s often the tests that get ignored first.

And once tests stop getting written as a normal part of development it starts getting tough to catch back up.

In fact, I’d guess that it starts getting exponentially harder to catch up. Not because of the quantity of the tests that need to be written. But because of the mental overhead of having to refamiliarize yourself with the feature and the code that the test must cover. The older the code the more effort it’s probably going to take before you’re able to write tests for it.

This however doesn’t imply that you cannot have good coverage without TDD, it just means that TDD makes it easier.