Test-Driven Development

In programming, test-driven development is when tests are developed first before the code is written.

In test-driven development the mantra has always been, red, green, refactor. Write a failing test and run it (red), make the test pass (green), then refactor it (that is look at the code and see if you can make it any better).[1]

Best Practices

Write the test that forces you to write the code you already know you want to write.

Avoid the central behaviors as long as possible. Don't go for the gold right away.

Decouple the production code from the test code by ensuring your tests are not 1:1 for the class methods or functions. Create and refactor as you go in production, but allow the tests to remain.

Why Use TDD


  1. https://github.com/gregmalcolm/python_koans
  2. Clean Code
  3. https://qualitycoding.org/3-laws-tdd/
  4. Examples of TDD in action

Last modified: 202105310500