I am writing some profiling tests for certain methods like adding customers (different batch sizes 100, 1000, 10000) to customers table in the database. I am using SqlCE database because of its support from LINQ.
Now to reach the ideal case, i am changing the database before every test so that every test will have same database. for that i am using File.Copy() but while using db.customers.FirstOrDefault() in the second test, i am getting the error “The database file may be corrupted. Run the repair utility to check the database file.”
I am clearing the data context after the test. The problem also may be with linq. I am not sure.Any idea of solving this. or any alternative to this approach. Any suggestions are required.
You should not do unit testing like that, it is error-prone and slow.
Instead, use database transactions, and rollback the data at the end of the tests, or when required (say per test).