Chapter 5. Enforcing Interface

An important part of doing test-driven development is defining the right interface. I’ve been drumming for a while now on the fact that a database is really an object and that it has a class. One of the properties of a class is that it tends to have a fairly strong interface.

In compiled languages, the validity of most coupling is enforced at compile-time. In dynamic languages, it’s validated shortly before you access part of an object. In databases, though, coupling isn’t validated until a command is transmitted to a database. This makes testing objects that talk to the database harder because mocking a database robs you of the feedback you get when coupling to it.

A way exists to give clients coupling to a database ...

Get Test-Driven Database Development: Unlocking Agility now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.