Top 5 benefits of test driven development (TDD)

Test Driven Development is the ‘bread and butter’ for modern agile software development teams. It is also one of the ways to ensure software quality.

In this article, I will briefly explain what is TDD, and the top 5 benefits of adapting Test Driven Development (TDD) in agile teams.

What is TDD?

Test Driven Development is a software engineering practice that writing a test based on the required functionality, before writing any implementation code.

In the beginning, the developer will write an automated test case based on the requirement. The first test will most likely fail on its first run. And then, the developer will write minimum code functionality to ensure the test passes. Once it is passed, the developer then “refactor” (or ‘improving’ the structure of code) to agreed team standards.

When to use TDD?

As a consultant, I often come across two kinds of people with two different thoughts.

Developers often believe TDD is good and fits in all projects.

However, product managers tend to think to apply TDD will increase the time to deliver to the market and adds little value to customers.

So, you may ask, “when should I use TDD”?

Okay, here is the catch, TDD is good for most situations, except rapid prototyping projects or thrown away code.

The reason is simple; what the customer wants is a quick and dirty solution that meets their requirements.

Besides, good engineers always apply what’s best for different situations. Agree?

Top 5 Benefits of Test Driven Development (TDD)

Okay, let’s get digging into the benefits of Test Driven Development and how it can apply to your situation at work.

  1. Well Planned Code 
  2. Prevent Breaking Previous Code 
  3. Evolve The Code Base 
  4. Code As Document 
  5. Prevent Bugs 

Benefit #1 – Well Planned Code 

I have worked with many developers in the past and asked for their feedback.

Ironically, they all came up with a similar answer, “I actually don’t have a full picture of how the system should integrate and what it needs to be done. I was told to do A so I just did it…”

Hence, writing tests first will enable developers to think about what they want to achieve from code, and how to integrate with the system as a whole. 

It will also give the developer an opportunity to learn from one another by clarifying the requirements before implementing the actual code.

Benefit #2 – Prevent Breaking Previous Code 

Imagine you have an empty bottle, you are now feeling thirsty and want to drink some water. And the good new is, you found a water tap nearby.

So, you turn on the water tap, and water starts to pour into your empty bottle. 

All the sudden, you realized there is a hole at the bottom and water starts dripping and you have no idea what to do. 

Does this sound familiar in the software development world?

Yes. It happens very often.

Thus, writing and running automated tests will increase the developer’s confidence with their work, as well as identify the last change has broken previous working code.

Benefit #3 – Evolve The Code Base 

One of the key principles in TDD is refactoring, refactoring often leads to well-design system architecture. 

TDD promotes good coding principles like KISS, YAGNI, SOLID and DRY.

Hence, developers are encouraged to write clean code, which ends up easy to modify, extend, test and maintain while design starts to evolve based on changing requirements.

Benefit #4 – Code As Document 

Most developers do not like to read written documentation for a system, they prefer to look into the code. 

With unit tests in place, developers can go to read the unit tests and find out how a class or library works. 

Since well-written unit tests provide a working specification for a piece of the function code, a lot of developers took it as a form of technical documentation that represents one part of the system.

Benefit #5 – Prevent Bugs 

When an agile team first practicing TDD, they may not get used to TDD results in more tests, which might take a longer test run times. 

However, with better code coverage, the team will end up saving time in the long run and reduce the time spent on fixing a bug that popped up in nowhere.

If there is a bug that comes up, the developer can write a test before attempting to fix the problem. This enables the developer to identify the real problem through reproducible steps.

Conclusion

TDD provides a great outcome when the code is constantly changed and improved. Developers can make changes on an application easily without having fear of breaking parts of it and impact day to day operation flow.

So, let me rephrase the top 5 benefits that can help an organization thrive.

  1. Well Planned Code 
  2. Prevent Breaking Previous Code 
  3. Evolve The Code Base 
  4. Code As Document 
  5. Prevent Bugs