views:

65

answers:

5

I intend to perform some automated integration tests. This requires the db to be put back into a 'clean state'. Is this the fastest/best way to do this?

var cfg = new Configuration();  
cfg.Configure();  
cfg.AddAssembly("Bla"); 
new SchemaExport(cfg).Execute(false, true, false);
A: 

Yes it almost is. You don't have to create a new configuration object before each test, you can reuse it when created once. You can make it faster by using an inmemory database like sql-lite for testing.

Paco
A: 

My integration tests do SessionFactory creation in a base class constructor, and SchemaExport in test fixture setup. I also test against SQLite running as an in-memory database for extra speed.

Ayende gave a good example of this approach in this blog post. Tobin Harris' article includes timing data of drop/create vs delete.

Lachlan Roche
A: 

Hello,

Me I use Proteus, it's an open source library. Before each test, there is an auto save of your set of data , load the set you want to test (an empty DB for exemple). After each test, the set of data is reloaded after the last test, the data present in the database before the tests are restored.

Kris-I
A: 

Since NHibernate is database independent another interesting option if you are having it generate your database is to run your tests against something like SQLite which is in memory. Things will run MUCH faster that way.

Here is an article on showing how to do this with ActiveRecord but you can take the concept and use it without ActiveRecord.

And here is a discussion if you're having trouble getting it working (I did at first).

ShaneC
A: 
            var se = new SchemaExport(conf);
        se.Drop(false, true);
        se.Create(false, true);
Fabio Maulo