TDD: Safety can be fun

Rabialco Argana
5 min readMar 21, 2021
Image Source from Unsplash

What is TDD?

Test-Driven Development or TDD is a software development process with a unique repetitive cycle. TDD also encourages the developer to think carefully about how the software will be used and what feature needed to provide the expected usability from what the client needs. Firstly, TDD starts with designing what feature needed by making a failing test without the code. After finishing the failing test, the developer writes the solution for the feature to pass the test that is made previously. The last one, after finishing the code developer makes an improvement to the code so it will have a good performance to the feature that is made.

TDD Cycle

In summary, the picture above is the main principle of the TDD cycle which is :

  • Write a failing test
  • Write a solution to pass the test
  • Improve your code solution

What’s the connection between TDD and Agile?

In the Agile approach, TDD is very important and very beneficial for the development process. One of the characteristics of Agile which always updates can be such trouble but, TDD is one of the best solutions for that because it will minimize the damage from previous work and increase safety for the code.

How to implement TDD in Agile?

In Agile, TDD is used by developing code in a certain way. Here is how TDD make the implementation of code in Agile development:

  • RED: In the first commit, the developer writes a failing test case that defines a desired improvement or new function.
  • GREEN: In the second commit, the developer makes code to pass the desired function test.
  • REFACTOR: In the third commit, the developer finally refactors the new code from the step before to suit the acceptable standards.
RED — GREEN — REFACTOR

Here is an example of the TDD implementation in the software development process:

  • RED

The first initiation of work to commit a test for the feature needed. In this step, the commit only contains the test so the pipeline will be failed.

[RED] Commit
  • GREEN

The second initiation of work to commit a code for the feature needed. In this step, the commit already finished which is suitable for the expected usability of the feature. But in this step not always has the best performance but finish the job.

[GREEN] Commit
  • REFACTOR

The third and the last initiation of work to commit an improvement of code for the feature needed. In this step, the commit consists of an improvement from the previous green commit to make the best code.

[REFACTOR] Commit

What are the benefits of using TDD?

There are many benefits of using TDD in your software development process like Agile. The benefits are :

  • Reduce Bugs

This benefit is caused by the making of the test first before writing the code. The result of the test can highlight mistakes and their impact on the system, so it will enable the developer to detect and fix bugs.

  • Identify functionality issues

By using TDD, it will make the developer check the functionality of the code that is being made. If they're an issue, the developer will easily found and fix the issue.

  • Avoid code duplication

This benefit is caused by the refactoring process that always reviews the code and improves it. The result is a best practice, clean code with a good performance.

  • Simplify code

This benefit is caused by the making of the test before writing the code. TDD requires developers to write code solutions for the test so it will promote code simplification.

  • Check the quality of code

This benefit is caused by the making of the test before writing the code. When checking your code with the test, there are quality metrics with a percentage so the developer know-how targeted the code that is being developed to the desired usability.

  • Safe for you and your code

With the step of TDD, the development process will benefit you and your code. This means TDD will prevent and keep the process from the unwanted things that can make the development process slow.

TDD Test Example

  • Unit Test
  • Functional Test

To conclude TDD is one of the approaches to the software development process. TDD is not required in every software development but very recommended to use in the process because it has many benefits to the team for a much easier development process.

Wow! Nice job finishing this article. Now you have mastered the basics of the TDD in Software Development. So are you ready to implement it in your work process?

--

--