nUnit测试寻找{assembly-name} .dll.config [英] nUnit tests looking for {assembly-name}.dll.config
问题描述
我有一个PowerShell脚本,可以将外壳程序打包为nunit-console-x86.exe
以在程序集(DLL)中运行测试,而这些程序集是通过外壳化为MSBuild来编译VS .sln
I have a PowerShell script that shells-out to nunit-console-x86.exe
to run tests in assemblies ( DLLs ) that were built earlier in the script by shelling to MSBuild to compile a VS .sln
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
中搜索这些配置设置,但是该文件不存在,因为我的脚本未创建该文件(出于下面说明的原因).
Some of these tests utilize System.Configuration.ConfigurationManager
to load config settings. nunit-console-x86.exe
searches for these config-settings in {$full_test_assembly_name}.dll.config
, but this file does not exist as my script does not create it (for reasons explained below).
每个测试项目.csproj都包含一个本地App.config文件.在Visual Studio中运行测试项目的测试时,nUnit会在本地App.config中搜索配置设置.这种行为符合我的预期.
Each test-project .csproj includes a local App.config file. When a test-project's tests are run in Visual Studio, nUnit searches for config settings in the local App.config. This behavior is as I expected.
我也有一个应用程序.sln,其站点/服务.csproj作为其启动项目,另外还引用了各种测试项目.当我从Visual Studio运行应用程序.sln的整个测试套件时,在为任何测试项目运行nUnit的测试时,nUnit都会在测试项目的本地App.config中搜索配置设置.
I also have an application .sln with a site/service .csproj as its startup project, plus references to various test-projects. When I run the application .sln's entire test-suite from Visual Studio, upon running tests for any test-project nUnit searches for config settings in the test-project's local App.config.
此行为与我预期的不同-我本以为nUnit会搜索位于启动站点/服务.csproj中的web.config.
This behavior is not as I expected -- I would have thought that nUnit would search the web.config located in the startup site/service .csproj.
作为一个实验,我从其中一个测试项目中删除了App.config.现在,当我在Visual Studio中运行其测试时,nUnit会抛出它找不到{test-project-assembly-name}.dll.config
的错误.因此,显然,uUnit默认情况下会在{test-project-assembly-name}.dll.config
中查找配置设置.
As an experiment, I removed App.config from one of the test-projects. Now when I run its tests in Visual Studio, nUnit throws errors that it can't find {test-project-assembly-name}.dll.config
. So apparently uUnit by default looks for config settings in {test-project-assembly-name}.dll.config
.
我希望我的测试脚本调用nUnit来运行测试组装测试,以便从web.config加载任何配置设置(我的构建脚本将其复制到构建目标dir中).
I want my test-script to invoke nUnit to run test-assembly tests so that any config settings are loaded from web.config ( which my build script copies into the build target dir ).
我该如何完成?我可以指示nunit-console-x86.exe
从作为参数提供的config-file-path中加载配置设置吗?我可以以不同的方式构造.sln和/或.csproj,以使uUnit利用Web.config进行配置设置吗?
How can I accomplish this ? Can I instruct nunit-console-x86.exe
to load config-settings from a config-file-path I supply as a parameter ? Can I structure my .sln and/or .csproj differently so as to cause uUnit to utilize Web.config for config-settings ?
推荐答案
解决方案是使用控制台开关/domain=multiple
.当您更改默认域使用情况设置以针对每个程序集使用单独的AppDomain时,它将导致NUnit加载项目app.config.此选项仅在NUnit 2.5或更高版本中可用.
The solution for this is to use the console switch /domain=multiple
. When you change the default domain usage setting to use a separate AppDomain per Assembly it causes NUnit to load the projects app.config. This option is only available in NUnit 2.5 or later.
nunit-console your.project.csproj /domain=multiple
这篇关于nUnit测试寻找{assembly-name} .dll.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!