TIDIDI

Rizal Alfaridzi
UKM Heroes
Published in
3 min readNov 8, 2019

Test Driven Development (TDD)

  • Test-driven development is a development concept when the tests are written before the code. In practical, Developer start the development process by writing unit-test before writing actual code implementation.
  • By doing this, we ensure that However the code implement, It’s not affecting the final goal.

Why do we need TDD?

throughout the time developing UKM Indonesia, i kind of wondering why do we still need to make test? even though i can still create a functioning webpage. Well i find the answer that we need to make our code Maintainable, it means that our code must have low coupling and high cohesion. one other reason why we need it, is we can lower the risk of bugs in our code , means that if we are not doing any testing to find out bug it will have a tremendous effects later on throughout the project, if our project large and you don’t implement TDD. it can be guaranteed that you will having hard times to find bugs in your project.

The cycles of TDD

TDD Cycle

you maybe wondering what are the meaning of RED , GREEN, Refactor. i will explain this shortly and briefly about those meanings :

RED

The red phase is always the starting point of the red, green, refactor cycle. The purpose of this phase is to write a test that informs the implementation of a feature. The test will only pass when the its expectations are met.

GREEN

The green phase is where you implement code to make your test pass. The goal is to find a solution, without worrying about optimizing your implementation.

REFACTOR

In the refactor phase, you are still “in the green.” You can begin thinking about how to implement your code better or more efficiently.

Let’s dive in to the test!

in UKM Indonesia, we use Angular framework for our project and Karma is a good friend of mine throughout the project. it’s a task runner for our tests. It uses a configuration file in order to set the startup file, the reporters, the testing framework.

from the code given above, we could see a very easy example of implementing TDD. we can find that there is the test to check whether the html has the <p> tag. maybe some people would think it’s just a normal test. But later on as your project is getting later this little test component can play a bigger role for your Maintainability.

Test Coverage

if you run the code ‘ng test’ in your terminal, Karma will run the test and shows the report of your tests that you have created. Here are the examples of the test report in UKM Indonesia

test result (THANK GOD IT ALL PASSED)

well that’s all i can tell to you all about the TDD. if i could find more throughout the development i will tell it later on in my next story.

THANK YOU !!!!!

--

--