What is TDD ??

Alice Richardson
4 min readDec 16, 2020

Have you ever come back to work on your previous code and have the issue of the code not working, WHAT they use to be working. What is happening?

A lot of time developers when looking at their code, you will hear a lot of them say WTF, the picture below going to show you between good and bad code quality.

Today we are going to talk about TDD(Test Driven Development) . This is going to help you curse less.

What is TDD (Test Driven Development)

Which has a simple principle in about 3 steps

  1. Begin by writing a failing test
    We will not have production code yet, so we will start by writing a test to prove it fails according to the test we thought it must fail. Writing a test we will not need to intercept in any case. We just write it enough for each of our workpieces.
  2. Write Production code
    At this stage, we will start writing the production code which will have to make all the parts we write the test pass through. As we don’t need to write code that is fancy or good, just test it through first.
  3. Manage Refactor code
    It will be easy to reach the last step. Because the code we wrote earlier in order for it to run the test, it will be short and easy enough for us to take that part of the code and rearrange it. Reduce duplication or adjust app performance or even tweak UI.

Of the 3 steps mentioned above It will repeat the work that is TDD’s lifecycle, which will end up in proportion to the workpiece and it allows us to see our code as a block of chunks, called modular, it gives us a clean look at the code, and as long as we keep testing, we don’t have to be afraid of editing from old code anymore.

What are the advantages of TDD?

Makes us write only the necessary code

We can see that TDD’s coding principles just need us to write to run the test and if we want to add new features or tasks. We always have to start by writing a test first.

Editing of work will be easier

Every time a new code is written. We can be sure that it will not interfere with old work or old code because there is always a test that works as a test suite to check the integrity of the system. This will greatly reduce the risk of mistakes that could happen.

Easy to Refactor Code

Writing a test is like we have a document in the system. If we want to refactor code anywhere, we can see it from the test that we created, which will give us a better understanding of the system.

Increased Test Coverage

We can be confident that the test that we wrote is covered in what cases. And does not cover any cases, still has room to make the test case better.

Debug is super easy

When we run the test fails, we will be able to know immediately which part it does not pass. Without having to waste time sitting around chasing all the code to find bugs.

Work according to the requirement

Another key aspect of TDD making is to pay special attention to the requirements of the workpiece. This gives our coding a clear stand. Because if we write code that does not meet the specified spec, it will fail to run the test.

What are the disadvantages of TDD?

In the early stages of TDD, it was quite slow. Since we are not used to thinking that “What will you do? And often we don’t understand problems and write tests even though we don’t understand. As a result, it almost did not help us. Plus, it may result in the production code being wrong as well.

Conclusion…

TDD is a work that must start from writing specifications always before writing code. Then we will come to the code according to the spec that you put it through. It’s easy to think of work if we don’t ask the customer’s requirement then how do we know what work we should do and send it to the client. Like TDD, if we don’t specify a spec then how do we know the actual code we should write? Is it enough to meet the needs of the customer?

--

--