# TDD

Test Last approach has shown its limitations over time since written tests are adapted to the code, introducing a confirmation bias. TDD adopts a Test First approach in which unit tests are written before code.

image-20201228223456530

# Three Phases of TDD

  1. Red. Write a unit test in failure.
  2. Green. Write a code sufficient to pass this unit test. Solution does not have to be ideal or optimized but should aim to pass the test ASAP.
  3. Refactor. Don't modify the behavior, but code is refactored.

# Clean Test

A clean test is characterized by its readability. A unit test must contain one concept and one assertion.

  1. Fast : test must be fast to be executed often
  2. Independent : tests must be independent.
  3. Repeatable : test must be repeatable in different envs.
  4. Self-validating : test result must be either success or failure.
  5. Timely : test must be written just before production code is made.
Last Updated: 3/1/2021, 9:19:08 PM