Test-Driven Development, Why?

This article is published for Individual Review in Software Engineering Project Course.

Stages in Test-Driven Development: Red, Green, Refactor (Image URL)

Test Driven Development (TDD) is software development approach in which test cases are developed to specify and validate what the code will do. Test-Driven Development starts with designing and developing tests for every small functionality of an application.

The purpose of Test-Driven development is creating simple and clear code, also minimalize the potential bug in our code.

  1. Better design and higher code quality
  2. Reduces the time required for project development
  3. Easier maintenace
  4. Detailed project documentation
  5. Constant feedback
  6. Minimalize potential bug

In Software Engineering Project Course we are required to use Test-Driven Development approach to develop the product in our project. There are three stages in Test-Driven Development which are: Red, Green, Refactor.

Red: Write a failing tests
In the first stage — the red phase, we should write a test for our future implementation. The test we made shows our expectation on how our code will works. In red phase, the test case will failed.

Example: Red Phase

Green: Write the implementation code to pass the tests
After created a failing test, we should implement our code as we expected it to be. Our test used as our guidance for the code implementation.

Example: Green Phase

Refactor: Write a higher quality code

Example: Refactor Phase

After passed the test, we are still allowed to modify our code. The purpose of modifying our code is to make a higher quality code for our project. By modifying our code, our test shouldn’t be failed again, it should still pass the test and have a better structure than before.

  1. Do not write any production code without a failing test first.
  2. Write only enough test code as is sufficient enough to fail.
  3. Only implement a minimal code that makes the failing test pass.