How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

前端 未结 5 1428
傲寒
傲寒 2020-12-23 16:02

We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5.

There are some unit tests that depend on a database. Setting up the app.config file in the

5条回答
  •  再見小時候
    2020-12-23 16:36

    I suggest to use this code (based on the answer of Jupaol):

    [ClassInitialize]
    public static void SetUp(TestContext context)
    {
        AppDomain.CurrentDomain.SetData(
            "DataDirectory", 
            context.TestDeploymentDir);
    }
    

    Usually this will create your database inside TestResults\\Out\ folder of your solution.

提交回复
热议问题