What is TDD and its phases?

Test driven development – TDD, as its name describes is based on test first approach. Tests drives the development. In a very simple language Test Driven Development is nothing but frequent or fast cycles of testing, coding and refactoring with testing before coding. The speed of these cycles is such that it’s not possible to do so in a manual way. Therefore TDD is a computer programming based methodology that consists of small rapid iterations.

TDD has the following steps:

  1. Think & write test cases
  2. Red – Failure of test case
  3. Green – Code and get the new test case pass
  4. Green – Ensure all old test cases also pass
  5. Refactor the code to clean it
  6. Repeat this cycle

TDD

As shown in this diagram, all these steps go in rounds. This method starts with writing the test cases for the newly identified functionality, after that production code necessary to make the test pass is written and after that code is refined by doing refactoring so that code is more maintainable. As we have written the tests before writing the code, it ensures we get immediate feedback after changes are made.  TDD (test-driven development) is a technique for designing the software as well as testing it.

  1. Think & write test case: In this step developer writes the test case without any code in front him. This is tricky, but ensures that the developer understands the functionality required and accordingly write the test case. The test case is not biased to show code works rather test cases are to test the expected feature
  2. Red – Failure of test case: In this step, you try to run the test case. As there is no code, you will get compile error itself. This is referred as Red stage indicating failure of test case
  3. Green – Code and get the new test case pass: In this step, the developer writes only the minimum required code to pass the test case just got failed. This becomes a challenging activity for developer who are used of writing code for the full module in one go. “Just enough” code concept helps in ensuring that no extra bit of code is going in. Developer again run the test case and make sure it passes
  4. Green – Ensure all old test cases also pass: Step 3 & 4 generally happens in one go. To make the understanding clear its bifurcated hire developer while testing the newly written code has to ensure that no old test case fails. This is nothing but continuous regression.
  5. Refactor the code to clean it: In this step developer refactor the code to ensure the functionality is intact and code is refined. In step 3 & 4 the focus is to write code only, whereas other important points for efficient design, maintainable code etc. are not considered. Refactor ensures it.
  6. Repeat this cycle: Step 1 to 5 are repeated multiple times in an automated manner so that all the features are covered in TDD cycles.

About Sparsh Goyal

A passionate IT professional, Sparsh Goyal boasts of 4.3+ years of experience. He has worked for various projects under AWS, Google Cloud Platform, Spring Boot, Python, Microservices, RESTful, RESTFUL APIs/SOAP, Scripting, Shell and JAVA. He is also working towards gaining proficiency in Oracle Cloud PaaS, DevOps, SaaS and Docker/Kubernetes. His primary and secondary skills validate his relentless pursuits of expanding his horizon and developing more as an IT person. He boasts of the following certifications: *Google Professional Cloud Security Engineer. *AWS Cloud Solutions Architect Associate. *Oracle certified JAVA programmer.

1 thought on “What is TDD and its phases?”

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top