Recreate and Reseed LocalDb Before Each Unit Test

后端 未结 3 2053
刺人心
刺人心 2020-12-14 11:22

I\'m attempting to write unit/integration tests for my ASP.NET Web API project and struggling to run each test in isolation. Allow me to explain.

I have a *.testset

3条回答
  •  暖寄归人
    2020-12-14 11:51

    In our current setup we're recreating the database schema before each class is loaded (with ClassInitialize attribute, but this could definitely be moved to AssemblyInitialize), and just seeding/cleaning up the database with the appropriate records before/after each test run (with TestInitialize/TestCleanup attribute).

    More info: http://msdn.microsoft.com/en-us/library/ms379625(v=vs.80).aspx

提交回复
热议问题