AndrewSwerlick
AndrewSwerlick

Reputation: 913

Prepopulating in memory SQLite database for Nhibernate testing

Currently, I have a unit test framework where I'm using a SQLite database in memory with NHibernate for unit testing. Each unit test runs in it's own session to ensure independence. For the most part, this works awesome, but as I'm approaching 150 tests, it's starting to run a little slow. The main reason for this, is that prior to each test I have to insert a good bit of data in the database.

Basically my application is a workflow app, and we store alot of information about the workflow (number of steps, fields on each step, etc.) in the database. The application can't run unless this stuff is there, so it's required for my tests.

At this point about 4 minutes of my total test time is spent on populating the database before each unit test. I'd love to make this population happen once per test execution, but since the in memory database is destroyed when the session is closed, I'm not sure how. Any suggestions?

Upvotes: 1

Views: 1075

Answers (1)

CL.
CL.

Reputation: 180240

You could copy a pre-filled database file to a temporary directory (on a RAM disk, if possible).

Alternatively, you can copy the contents of a database into your memory database by using the SQLite backup API.

Upvotes: 4

Related Questions