Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do TDD efficiently with NHibernate?

It seems to me that most people write their tests against in-memory, in-process databases like SQLite when working with NHibernate. I have this up and running but my first test (that uses NHibernate) always takes between 3-4 seconds to execute. The next test runs much faster.

I am using FluentNhibernate to do the mapping but get roughly the same timings with XML mapping files. For me the 3-4 second delay seriously disrupts my flow.

What is the recomended way of working with TDD and NHibernate?

Is it possible to mock ISession to unit test the actual queries or can this only be done with in memory databases?

like image 706
maz Avatar asked Dec 01 '08 22:12

maz


1 Answers

I am using the Repository Pattern to perform Database operations, and whenever I run my Tests I just run the higher-level tests that simply Mock the Repository (with RhinoMocks).

I have a seperate suite of tests that explicitly tests the Repository layer and the NHibernate mappings. And those usually don't change as much as the business and gui logic above them.

That way I get very fast UnitTests that never hit the DB, and still a well tested DB Layer

like image 54
Tigraine Avatar answered Sep 23 '22 16:09

Tigraine