Test-Driven Development (TDD) Advantages

Learn about TDD advantages and disadvantages of TDD.

Imagine two people, A and B. They’re working on the same task. Both are equally skilled, charming, and delightful people motivated to do a high-quality job as quickly as possible. The task is not trivial, but not wildly complex either. For the sake of discussion, let’s say it’s a new user logging into a website and entering some detailed pertinent information.

At this point, we might think it’s taken B more time to write the method. However, B has written code that’s more likely to be:

  • Correct
  • Robust
  • Easy to maintain

But there’s a good chance B will be done before A even though B is taking on the additional overhead of writing tests.

Let’s watch our programmers as they keep working.

Advantages of automated testing

It’s usually faster to run multiple verifications of the code as an automated test than to always check manually, and that advantage only increases as the code gets more complex. Additionally, the automated check does a better job of ensuring that steps aren’t forgotten.

Advantages of accurate testing

There are many beneficial side effects of having accurate tests. We’ll have better-designed code in which we’ll have more confidence. But the most important benefit is that if we do testing well, our work will go faster. We may not see it at first, but at some point in a well-run, test-driven project, we’ll notice that we have fewer bugs and that the bugs that do exist are easier to find. It’ll also besimpler to add new features and modify existing ones. Furthermore, we’ll do better on the only code-quality metric that has any validity: How easy it is to find incorrect behavior and add new behavior. It’s sometimes hard to pin down the benefit of testing because good testing often feels like we’re doing an excellent job just programming.

Disadvantages of testing

The tests can also have bugs. They can also be slow. Environmental issues may mean that things that do work in a test environment won’t work in a development environment. Code changes will break tests. Adding tests to existing code is an additional pain. As with any other programming tool, there are many ways to cause ourselves trouble with testing.