TDD: Safety can be fun

Image Source from Unsplash

What is TDD?

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?

How to implement TDD in Agile?

  • 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?

  • 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

  • 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?

Writer with a Big Dreams