Test-driven Development

Priagung Satria
2 min readMar 21, 2021
source: https://geek-and-poke.com/geekandpoke/2013/7/28/tdd

TDD is very common nowadays as there are so many advantages and almost no real disadvantages.
Test driven development means creating a test unit first before you create the code.
The purpose of doing this is so you can create a code that simply accepts the tests and gives the correct output according to the inputs.
The sole aim of doing TDD is so the code created is creating the simplest possible code to pass all the tests that were created.

source : medium.com

Why should we implement TDD?

TDD is a beneficial practice, it has been proven that TDD can reduce the number of bugs per code written rate and also improve the code quality.

Disadvantages

  • Use it or drop it
    Your whole project will have all be created based on test first,
    if you extend the features without creating tests first it defeats the purpose of Test driven development
  • TDD is hard for UI development
    Testing each individual placement of an UI component is pointless
    because when an UI moves or changes you will have to rewrite the tests.
    However you should use TDD on the controller and models to test all the functions that are created.

TDD against Traditional Testing

  • In TDD you will achieve 100% Coverage test as the code you write solely for creating solution to the tests made
  • Traditional testing is more consuming especially on larger scale projects as you need to carefully conduct all the tests needed more thoroughly.

How to implement TDD on your project?

The cycle of TDD is

  1. Creating test
  2. Write code that can run the tests.
  3. Change the code to make it better
  4. Rinse and Repeat

For example we’ll apply Red, Green, Refactor Tags on our commits for all of our commits, this will indicate the current development in three phases.

  • Red
    This red tag for commit that have unit tests that are needed for the feature that you want to develop
  • Green
    This green tag is for writing the code to pass the tests that have been made previously.
    The goal of this phase is to create the simplest solution to the tests that gives the correct output.
  • Refactor
    This refactor tag is created solely for improving the existing code to become cleaner, simpler or even more efficient.

This sums up my experience regarding TDD in my current project
hopefully it can also be helpful to you.
Thank you for reading

:)

--

--