← Main page

TDD

Why to use TDD?

Test driven development (TDD) reduces feedback cycle time and allows to work in small iterations which makes development easier.

How to use TDD?

  1. Define an acceptance criteria and write a test. It may be a unit test or an e2e test. It is easier to start with a unit test but if your tasks are small enough (up to 1-2 days of work) it will be also not difficult to write an e2e test first as well. Make sure the test fails.
  2. Write an implementation. Make sure the test passes.
  3. Refactor if necessary.

Limitations

  1. Usage of TDD makes sense if you can run your test in up to 5-20 seconds. If it takes longer you need to reduce the time first. The main advantage of TDD for me is that I can think about my task in terms of an actual result and edge cases. When I know what exactly needs to be implemented I can go to implementation.
  2. I don't try to design programs using TDD. The main benefit for me is a clear automated acceptance criteria and small amount of code I need to write to implement logic for the acceptance criteria.
  3. I use e2e tests for testing the whole system and unit tests for testing business logic in isolation. I need both of these types of tests.