I never tried DbUnit
. What I do with nHibernate is creating test suites that create the database & data at setup (using both SchemaExport
and batch inserts), then run tests that check both entities and queries.
I use local development databases such as SQL Server Express
of Oracle Express Edition
depending on the project.
In one very large project I was part of, we used the Rollback technique
. Each test was creating a transaction which was rolled back at the end. This is described here.
But there is a better way of testing. Yesterday, I read a book called nHibernate 3.0 Cookbook from Jason Dentler in which the author propose a method called Fast testing with SQLite in-memory database.
I didn't test it yet, but that recipe is fully detailed and looks promising.
I'm sure you can download the sample code somewhere (wasn't able to find it quickly), but I highly suggest to buy the book. It contains various other test techniques such as Fluent nHibernate Persistance Tester and Ghostbusters test.
That technique is also explained in this blog post.