运行 nunit 从项目和解决方案中测试时的不同行为

Different Behavior when running nunit tests from project and from solution

我在一个包含许多测试的解决方案中有多个项目,其中一个使用实体并具有以下行为: 如果我右键单击 运行 我项目上的所有测试,一切都会 运行 顺利,但是如果我右键单击我的解决方案并执行相同的操作,我会得到:

System.InvalidOperationException : No connection string named 'Entities' could be found in the application config file.

我的 App.config

当然有这些行
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/Sales.csdl|res://*/Sales.ssdl|res://*/Sales.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\v11.0;attachdbfilename=&quot;C:\Users\louis gentil\Documents\Visual Studio 2013\Projects\TFS\LouisGentil\SQL\ModuleSQL-Database.mdf&quot;;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>

kif 询问的更多信息:

您是否知道可能导致此行为的原因?

尝试在 ReSharper → 选项 → 单元测试中选择 "Use separate AppDomain for each assembly with tests"。这是 ReSharper 进行的一项优化,它重用了 AppDomain(它们的设置成本很高),但副作用是只能加载一个 app.config,而且可能是错误的。