What is Test Driven Development (TDD)?

All code is guilty until proven innocent

Test Driven Development (TDD) is a software development process in which a developer writes test of their code before writing the code itself. The test-first concept encourages repetition of very short development cycles with the writing of just enough code to pass the test.

The main idea of the approach is to catch all bugs before they can make any harm to the program in development. It gives the developer an extra space to think about what they are implementing before they actually start implementing it. The divine mantra of Test Driven Development is “red/green/refactor”, where red means fail and green means pass.

Test Driven Development lifecycle

TDD was originated by software engineer Kent Beck, who described TDD lifecycle in his book “Test Driven Development: By Example”:

    1. Add a test
    2. Run all tests and see if the new test fails
    3. Write the code
    4. Run tests
    5. Refactor code
    6. Repeat

Test Driven Development

Pros and cons of Test Driven Development

  1. Comprehensive test coverage – all written code is covered by at least one test
  2. The greater level of confidence in the code
  3. Well-documented code
  4. Understanding the requirements before writing the code
  5. Continuous integration
  6. Increased productivity
  7. Reinforced mental model of the code
  8. Focus on design, interface, and functionality of the program
  9. No need in tedious debugging
  10. More stable system

Still, Test Driven Development has several cons:

  1. More code is required with TDD than without TDD
  2. False sense of security due to a large number of tests
  3. Maintenance overheads
  4. Additional time for an excessive number of tests
  5. Requires to know how to set up and use a testing environment
  6. Takes time and efforts to become proficient in TDD
  7. Too much TDD makes the code more complicated than necessary
  8. Discourages big picture design
  9. Higher cost

Follow the leaders
Many giant companies value Test Driven Development approach for its ability to increase accuracy and productivity, enhance confidence in the code, create roadmaps and logical paths for the product in development, as well as to make the code more modularized, extensible and flexible. Among them are big fishes like Google, Facebook, Spotify, Etsy, Buffer, and many more.

Your most satisfying code

A Ruby on Rails community is well known for their not compromised approach to a code quality and it treats TDD as a part of their conventions. Regardless of the fact that Test Driven Development may seem counterintuitive at the first glance, it can greatly help achieve good quality code and great test coverage. It helps make the code better structured, simpler, and better understandable and considerably reduces the number of bugs that pop up unnoticed.

 

CTO at LaSoft

1 comments On What is Test Driven Development (TDD)?

Leave a reply:

Your email address will not be published.

Share This