Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 905
Draco Avatar asked Nov 26 '22 21:11

Draco


2 Answers

TDD is a coding and design-in-the-small technique. It is not a big-picture envisioning technique. If you starting to write an application, you want to do some storyboards, or wireframes, or even some simple sketches. You should have an idea about the larger-scale design i.e. the classes and relationships in your system. Before you get to the point where you'd start to do interaction design (e.g. methods and arguments) you start doing TDD.

The wireframes you have done will give you an idea of how the system should appear. The large scale design will give you an idea of what classes to create. However, none of these models should be considered correct or permanent. As you write tests, you'll find better design ideas that will change your high-level design, and even your wireframe design.

like image 159
Uncle Bob Avatar answered Dec 24 '22 14:12

Uncle Bob


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.

like image 30
Jon Skeet Avatar answered Dec 24 '22 15:12

Jon Skeet