What is Test-Driven Development? (TDD)

Karan S. Chauhan
3 min readJan 17, 2021

--

Test-Driven Development (TDD) is a software development method where tests are generated to specify and validate what the code is supposed to do. It’s a style of programming that concentrates on creating unit-tests (for each functionality) and design (refactoring previous code).

TDD can be summarized by the following:

  1. Write a single unit test for an aspect of the program
  2. Run the test
  3. Write enough code to make the test pass
  4. Refactor the code
  5. Repeat (For each aspect of the program)

Test-Driven Development starts with the design and development of tests for every functionality of an application. This methodology allows developers to write new code, only for the part of the program, where the test had failed. This results in less duplicated code.

You might be asking yourself, why use Test-Driven Development? Why not just stick to traditional methods? Well the following points made a lot of sense as to why TDD may be a better option over Traditional testing methods.

  • With Test-Driven Development, there’s a 100% coverage for the tests. Every line of code written is tested, as opposed to traditional methods.
  • Traditional testing focuses on test case design rather than Test-Driven Development where the focus is on creating production code that will verify that the tests work properly.

After deeper research, I found that there are 2 types of Test-Driven Development. Acceptance TDD and Developer TDD.

Acceptance TDD: (Focus is on the overall system behavior)

  • Write a single test
  • Write just enough code to fulfill that test
  • Also known as Behavioral Driven Development (BDD)

Developer TDD: (This is generally called Test-Driven Development)

  • Write a single test for each small functionality of the system
  • Write just enough code to satisfy that unit test

Benefits of Test-Driven Development:

  • Significant reduction in defect rates
  • Less effort required during the final stages of development

Common Issues with TDD:

  • Creating too many tests at once
  • Writing tests that are too broad
  • Only a few developers use this method instead of the entire team
  • Poor maintenance of the tests

Test-Driven Development is great at detailing specifications and validations. However, it doesn’t do as great when bigger issues are in consideration. For example, TDD doesn’t work well enough when the overall design, system usage, or the user interface are important. In this case, Agile Model Driven Development (AMDD) is recommended, which I’ll go over in another article.

Resources:

--

--

No responses yet