Skip to content

Test-driven development

Test-driven development is one of the techniques of creating software. By creating software with TDD, you need to continuously repeat these steps:

  • Red
  • Green
  • Refactor

Stages of creating software

Red

In this step the user needs to create a test which checks a certain functionality. With no code to check against the test will fail. The main code does not exist.

Green

The second step in writing the first functional revision. At this point the test written in step one should pass but the main code will have some residual errors.

Refactor

The last stage is code refactor which cleans the code so that it fulfills certain standards (like SOLID and DRY).

tdd

TDD in details

What can't be understood as TDD.

  1. It's not a technique of writing tests. Tests should look like in their "usual" form when you are writing software.
  2. It's not a definition of how a code function should look.
  3. It's not a way of substituting testers with developers. Testers are always an important part of software development.

Benefits of TDD

There are many benefits of using TDD such as:

  • It forces you to cover your code with tests.
  • Any conceptual errors are found during writing tests.
  • Code modification is safer - we can always check if we had not broken anything by executing exisitng tests.
  • Requirements are also showcased by looking at the tests themselves.
  • Insufficient requirements are identified at an early stage of application creation.
  • The project can be finally written a lot faster than in classical approaches.

Disadvantages of using TDD

Similar to all other approaches TDD has also some drawbacks:

  • The project has to have good requirements and documentation written down (which is missing in most cases).
  • At the beginning of the project the production code is created rather slowly.
  • Any change in requirements implies a lot of change in source code.