views:

63

answers:

2

Hi,

BACKGROUND:

  • I've running unit tests in VS2008 using MSTest.
  • My project has a SqlLite database.
  • I have found that I needed to arrange for the default database file to be copied to the MSTest area for the test to be able to find it. I am using the following annotation about the test code to arrange this: [DeploymentItem("database.db3")]

ISSUE:

  • When I run the "all tests" at once via VS2008 I get the below-mentioned error on one of the tests. When I run this test alone it passes fine.
  • The error I am getting is: "System.Data.SQLite.SQLiteException: The database file is locked database is locked"
  • Again, when I run the test that throughs this issue alone it works fine & passes

QUESTION:

Any ideas/suggestions regarding how to address this issue? Is it due to the way I'm manually copying the database file for each test (i.e. each test I have one of the above-mentioned annotations)

Example of full test:

/// <summary>
///A test for process
///</summary>
[TestMethod()]
[DeploymentItem("database.db3")]
public void processTest()
{
    Coordinator target = new Coordinator();
    target.MyConfig.clear_database();

    target.process();
}

Thanks

+1  A: 

Sounds like the first unit test to run leaves the DB file open. Be sure to close the DB file.

Try using a [TestInitialize()] method in you test fixture to copy/create and then open the DB file while using a [TestCleanup()] method to close and then delete the DB file.

jenglert
the problem is I couldn't work out how to manually copy the file, noting the directory changes each test run. Hence I used the "[DeploymentItem("IntranetSync.db3")]" approach which seems to work. Is there a equivalent way to delete? (i.e. noting I'm not really sure how to manually hook in a script that would do the deletion)
Greg
A: 

Call static method SQLiteConnection.ClearAllPools() or SQLiteConnection.ClearPool() just before you want to delete the database file.

TTT