Test-Driven Development – Are TDD Tests Always Unit Tests?

tddtesting

I understand test-driven development so far that you are only allowed to write productive code when you have a failing (red) unit test.
Based on this I have the question if the test-driven approach can also be applied to other forms of tests.

Best Answer

All TDD requires of you is that you write a failing test, then modify your code to make it pass.

Typically "unit tests" are small and fast and test some part of your code in isolation. Because they are fast, it makes the red/green/refactor loop fast too. However, they suffer from only testing parts in isolation. So you need other tests too (integration, acceptance etc). It is still good practice to follow the same principles: write a failing test, then modify the code to make it work. Just be aware that they are typically slower, so can affect the red/green/refactor cycle time.