What is the purpose of the TDD?

  1. Minimize the number of bugs. Correcting bugs means investing time, which translates irremediably into money that is not wasted. Time is money and the fewer bugs we have to correct, the more profitable our project will be (and less headaches and frustration too!).
  2. Implement the just functions that are needed at that moment. Every programmer knows how good it could be to implement different functionalities that add value to an application. But make no mistake, if for example a customer has asked us something specific; better give it to optimize the work invested. Thanks to this method we eliminate that time of code that the responsible of the app has not requested. Efficiency and profitability as fundamental objectives.
  3. Produce modular software and highly reusable and prepared for the change. With this technique we do not have to worry if there are rotations of programmers and that they use that same code. There is no risk of them breaking the code. Everything written has been previously tested, so any change that you want to implement is covered by the tests.

Help split a problem into smaller portions and make sure it has no errors.   It is a way of measuring that is being developed in the right way and also the time you invest in each stage of this process. First write code and then try it, a very natural process, and right? But we could do the reverse: start with the tests and then write the code that the test wants to test. Here resides the kit of the subject and that collides with the instinct of the programmer.

Advantages of starting to use TDD if you are a programmer:

  1. Productivity. We avoid writing more code than what is really needed. Using TDD, you solve fractional tasks and overcome specific tests, which help to optimize the time invested much better.
  2. Tranquility. When following the TDD process, all the code written after performing the tests is fully protected. This results in a fresh, clear and clean code.
  3. Scalability. Every project becomes great as it deepens into it. This results in an increase in the complexity of the code. TDD allows us to evaluate at what point we are in each moment to do a quick check of “how are we going?”.
  4. Refactoring. After finding a problem, we go through the process of refactoring it, so we do not have to wait for the finished code to be able to carry out this task, but the code is rewritten as errors are detected.
  5. Debugging. TDD is the best way to detect faults, if one appears and we modify the code until the test passes, we will gradually debug it and obtain a clean code.

Disadvantages of the use of TDD:

We must bear in mind that not everything is perfect and TDD has some slight inconveniences when it comes to implementing it in a project. The two most relevant to take into account would be the unidentified errors and the learning curve.

  1. The unidentified errors:

Just by passing all the tests on the tool that is used does not mean that there are no errors, it only means that the tests that have been run have not found any errors. This can cause a false sense of security, so it is necessary that the tests are detailed and cover all hypothetical possible scenarios.

  1. Learning curve:

TDD is a difficult technique to adopt in the short term and has a high learning curve, which means that our productivity will be reduced during the first months of use, but afterwards it will compensate remarkably the effort invested. It is advisable to carry out specialized training to minimize the impact of this fall in productivity to a minimum.