gpt4 book ai didi

visual-studio-2010 - nUnit 测试寻找 {assembly-name}.dll.config

转载 作者:行者123 更新时间:2023-12-01 01:15:01 25 4
gpt4 key购买 nike

我有一个 PowerShell 脚本,可以输出到 nunit-console-x86.exe通过对 MSBuild 进行脱 shell 以编译 VS .sln,在脚本中较早构建的程序集 (DLL) 中运行测试

Exec { invoke-expression "$BUILD_DIR\Tools\NUnit.2.5.10.11092\nunit-console-x86.exe  $full_test_assembly_name /xml:test-results/$test_results_file_name" }

其中一些测试使用 System.Configuration.ConfigurationManager加载配置设置。 nunit-console-x86.exe{$full_test_assembly_name}.dll.config 中搜索这些配置设置,但该文件不存在,因为我的脚本没有创建它(原因如下所述)。

每个测试项目 .csproj 都包含一个本地 App.config 文件。当测试项目的测试在 Visual Studio 中运行时,nUnit 会在本地 App.config 中搜索配置设置。这种行为正如我所料。

我还有一个应用程序 .sln,其中一个站点/服务 .csproj 作为它的启动项目,以及对各种测试项目的引用。当我从 Visual Studio 运行应用程序 .sln 的整个测试套件时,在为任何测试项目运行测试时,nUnit 会在测试项目的本地 App.config 中搜索配置设置。

这种行为与我预期的不同——我原以为 nUnit 会搜索位于启动站点/服务 .csproj 中的 web.config。

作为一项实验,我从其中一个测试项目中删除了 App.config。现在,当我在 Visual Studio 中运行它的测试时,nUnit 会抛出无法找到的错误 {test-project-assembly-name}.dll.config .所以显然 uUnit 默认在 {test-project-assembly-name}.dll.config 中查找配置设置.

我希望我的测试脚本调用 nUnit 来运行测试程序集测试,以便从 web.config 加载任何配置设置(我的构建脚本将其复制到构建目标目录中)。

我怎样才能做到这一点?可以指导吗 nunit-console-x86.exe从我作为参数提供的配置文件路径加载配置设置?我可以以不同的方式构建我的 .sln 和/或 .csproj 以便使 uUnit 利用 Web.config 进行配置设置吗?

最佳答案

解决方案是使用控制台开关 /domain=multiple .当您将默认域使用设置更改为每个程序集使用单独的 AppDomain 时,它会导致 NUnit 加载项目 app.config。此选项仅在 NUnit 2.5 或更高版本中可用。

nunit-console your.project.csproj /domain=multiple

关于visual-studio-2010 - nUnit 测试寻找 {assembly-name}.dll.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12571877/

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