gpt4 book ai didi

c# - MSTest 失败 : Failed to find configuration section 'log4net' in the application's . 配置文件

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:27 28 4
gpt4 key购买 nike

这是我的设置:

/
solution.sln
Core/
Core.csproj
web/
web.csproj
Web.config
Test/
Test.csproj
App.config
build/
_PublishedWebsites/web/etc...
test.dll
test.dll.config
Core.dll
log4net.dll

我在 Test 项目中编写单元测试来测试 Core 项目的功能。所有项目都使用 log4net,所有项目都使用相应的 App.configWeb.config 文件进行配置

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

在他们的 AssemblyInfo.cs 中。

项目是使用 NAnt 构建到 build 目录中的。

当我从 Visual Studio (2010 Professional) 运行单元测试时,一切正常。

但是当我尝试直接执行 MSTest 时

MSTest.exe /resultsfile:TestResults.trx /noisolation /testcontainer:build\test.dll

所有测试用例都失败并出现以下错误:

log4net:ERROR Failed to find configuration section 'log4net' in the application's .config file

这让我感到困惑,因为 test.dll.config 文件肯定包含 log4net 配置部分。

MSTest 创建的文件夹还包含配置文件:

/flopes_MyMachine 2015-10-08 08_48_59/Out/
Core.dll
test.dll
test.dll.config
log4net.dll

在我看来,可能 MSTest 使用了错误的配置文件,或者没有找到 test.dll 的配置文件?这有意义吗?有没有办法告诉 MSTest 使用哪个配置文件?

我做了一个小的测试输出来查看加载了什么配置文件,它增加了更多的神秘感,因为显然加载的配置文件是:

D:\Programme\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe.Config

这怎么可能?为什么 MSTest 不加载就在 test.dll 旁边的配置文件?这有什么意义?

最佳答案

我会看看这个问题和答案:MSTest.exe not finding app.config

它指出您应该创建一个测试运行配置,其中包括 .config 作为部署项。

还要检查正在使用的配置是否正确;查找事件配置文件的方法:

// Get the user-config:
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath

// Simple approach
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile? Is it the correct .config

通过@florianpeschka 检查几件事情让我们相信问题出在 noisolation 标志上。这有点奇怪,因为 noisolation 基本上控制为测试实例创建单独的沙箱,但可能需要创建单独的进程才能使用“动态”和非硬编码配置ms 测试。

所以简而言之,不要使用 noisolation 标志,一切正常。

关于c# - MSTest 失败 : Failed to find configuration section 'log4net' in the application's . 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901730/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com