Why would we want to use tests driven development with models?

tdd

#1

Question

Why would we want to use tests driven development with models?

Answer

By performing tests on the models of our application, we make sure that the main functionality performs properly even before we involve other parts of the application that might make finding a bug more difficult, like having interaction with the browser.

Let’s imagine it is a cold day and we need to go outside, we layer up with sweaters and coats and as we walk around we start getting an itch on our arm, because of all the sweaters and coats we cannot find how to scratch that itch. The same way gets to be with bugs in our code, we may get error messages but since it may come from another part of the app, or the browser itself, we will need to trace it to the source. Having tests on our models we make sure that they work properly in close similarity to a real-life situation.

It is not to say that Test Driven Development will only be efficient with models, there are many parts of the app that can be tested, models are just one part.