I would like to unit test a DEPENDENT service layer which allows me to perform CRUD operation without mocking using NUnit. I know this is probably bad practice but I want to give it a try anyway – even if the tests have to run over night. My data is persisted using NHibernate and I have implemented a little library that ‘bootstraps’ the database which I could use in a [Setup] method. I am just wondering if someone has done something similar and what the fastest method for bootstrapping the database is. I am using something like this:
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly("Bla");
new SchemaExport(cfg).Execute(false, true, false);
to establish the db schema. After that I populate some lookup tables from some Excel tables.
Any feedback would be very much appreciated. Thanks.
Christian
Ayende has a good example of this approach in this blog post. His example is shown below with my comments.
As the Configuration is expensive to create, it is created only once per test run. A SQLite in-memory database is used as this is the fastest way to do queries.
When using this, each test starts by creating required data.