The Neuronen Schmiede concerns itself with topics related to software development. One focus are robust web applications.

Locking the Database Away from Unit Tests

Permalink

Unit tests are supposed to be fast. Connecting to and querying a database is slow.

In a typical Ruby on Rails project it is easy to write unit tests that talk to the database. A model has a direct line to the database. One wrong method call and the test case is already talking to the database.

Making the database inaccessible in all unit tests would make the tangled mess visible and enforce a separation between infrastructure and domain. It also raises awareness that the database is a dependency and has a cost.

What do you think of this idea? How would you implement it? I'm curious, send me an email or tweet at me.