I have a code that first uses the EF code that I want to test Unit in my unit test, I want an empty real base to be created at the beginning of the test , so I did:
[TestInitialize]
public void Initialize()
{
Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());
}
[TestCleanup]
public void CleanUp()
{
MyContext db = new MyContext();
db.Database.Delete();
}
but due to the fact that the tests are executed in parallel, this does not work, so I conducted an order test with my tests, and also has problems, because the database is sometimes not discarded, because it is used ... Someone has a better strategy ? I thought maybe each test will create its own database? if it is a good idea, how can I achieve this?
source
share