Software Development Blog

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.

Comparison of Software Development Process Types

Feature Waterfall Agile Test-Driven Development (TDD)
Approach Sequential design process Iterative and incremental process Test-first development process
Flexibility Low flexibility; changes are difficult and expensive High flexibility; adapts to changes rapidly Moderate flexibility; changes are incorporated through ongoing testing
Testing Conducted after the development phase Continuous throughout the development cycle Integral part of the development, tests are written before code
Documentation Heavy emphasis on documentation Less emphasis, prioritizes working software Documentation through test cases
Feedback Loop Long feedback loops, mostly during testing phase Short feedback loops, continuous feedback through iterations Continuous feedback via failing and passing tests
Project Size Suitability Better suited for small to medium-sized projects with well-defined requirements Suitable for projects of various sizes, especially where requirements are expected to change Best suited for projects where code robustness and quality are critical
Risk Management Risks identified and addressed during specific phases Risks are managed continuously and iteratively Risks in code functionality are identified and mitigated early

Leave a reply:

Your email address will not be published.

Welcome to check our projects

We have described the most compelling solutions and approaches to meet challenges and advantages.

Share This