3

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?

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

3 Comments

I'm using Sharp Arch., where should I put this?
new SchemaExport(config).Execute(false, true, false, session.Connection, null); should be just before running the test case with the session the test case uses. How to get the config from Sharparch i don't know
The one sentence in your answer, "Sqlite inmemory databases are ... so each connection has its own database" was an "A-Ha" moment for me. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.