Tag test driven development

What is Test Driven Development (TDD)?

Test Driven Development (TDD) is a type of development with automated tests. It is an approach towards clean code.

Two simple rules of Test Driven Development (TDD) are –

(1) Write new code only if an automated test has failed and (2) Eliminate duplication. These 2 rules are followed by the tasks of programming which are called as TDD mantra (Red/green and refactoring).

Test Driven Development (TDD) Mantra

Red – Start simple with a little test that does not work

Green – Make the test work quickly by making changes to the code

Refactoring – Eliminate dependencies (path to clean code)

According to Kent Beck (author of Test-Driven Development by example), rhythm of TDD is as follows –

  1. Quickly add a test
  2. Run all tests and see the new one fail
  3. Make a little change
  4. Run all tests and see them all succeed
  5. Refactor to remove duplication

Refer this book – Test Driven Development by example by Kent Beck to learn about TDD, he has beautifully explained the concepts with a live example and patterns for TDD.