Test Driven Development is the way to go. But how should it be done

tdd

A number of developers are designing their applications using Test Driven Development (TDD) but I would like to know at which stage should I incorporate TDD into my projects? Should I first design my classes, do some unit tests and determine what methods are needed or design methods first and then do some unit tests after?

What is the best way to go about this?

Best Answer

The point of it being test driven is that the tests drive the design as well as the implementation.

In some cases that's not appropriate - it may be blatantly obvious what the design should look like, especially if it's implementing an existing interface (or some similarly restricted choice) but when you've got a large "design space" TDD encourages you to writes tests demonstrating how you want to be able to use the class, rather than starting off with you how you think you want to implement it.

Generally if something is easy to test, it will be easy to use.

Related Topic