Introduction to Test-Driven Development
One of the worst experience in coding, debugging. Especially if your code consists of hundreds of lines, you have to check every line in your code to know which part needs to change so that your program works as intended.Fortunately there is a way to avoid getting a bug and that is Test-Driven Development(also known as TDD).
What is TDD?
TDD is a software development process in which requirements are turned into a test case and write codes so that the test passed. There are 3 stages to determine which process should be taken: RED, GREEN and REFACTOR.
RED
Red stage is the stage where we write tests with their requirements and purposely failed the test. The test should be simple and focus on 1 function of the requirement,thus 1 feature can have multiples of tests, writing tests first could give a goal to you on what to do.In Git the stage will be displayed in the commit by writing ”[RED] comment written here” and it will be shown as progress.
GREEN
Green stage is the stage where you will be writing codes in your main program to pass the tests that was made, writing the codes should be only to pass the test and not add any lines that are not correlated to the tests. After passing the tests it is ready to move to the next stage, in Git it will be displayed as “[GREEN] expecting comment” showing that the specific test has passed.
REFACTOR
During this stage you are able to do minor changes to your code, minor changes mean applying clean code and not changing your code so that it fails.This is to ensure your code is flexible and simple, in Git it will be displayed as “[REFACTOR] expected comment” showing the minor changes applied.