Afshar
Afshar

Reputation: 11483

SQLite in memory unit testing show "no such table error" instead of real error message

I have a simple NHibernate based application that I'm unit testing it with in memory SQLite. Whenever the test fails, for example because of duplicate entity, the unit test fails with error 'there is no such table TABLE_NAME' error instead of showing original error.

If I switch to real file database, all tests (passed or failed) are evaluated correctly. How this is possible at all and how can I correct this?

Upvotes: 3

Views: 2823

Answers (1)

Firo
Firo

Reputation: 30803

this is often caused by not using SchemaExport with the inmemory database. Sqlite inmemory databases are dependend on the connection, so each connection has its own database.

new SchemaExport(config).Create(false, true); // creates database, fill it and throws away

instead of

using (var session = sessionfactory.OpenSession())
{
    new SchemaExport(config).Execute(false, true, false, session.Connection, null);

    // use session in test
}

Upvotes: 3

Related Questions