问题
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" }
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).
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.
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.
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.
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
.
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 ).
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 ?
回答1:
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
回答2:
The quick answer is that NUnit doesn't manage config files. It leaves the handling of configuration files to the framework:
http://nunit.net/blogs/?p=9
If you want NUnit to use a specific configuration file, you can create an NUnit project, and copy the configuration file you wish to use into [NUnitProjectName].config. This configuration file would need to reside in the same directory as your NUnit project.
回答3:
Not sure if this still applies to the OP's question , but when you build the test project multiple .dll.config files are copied over . If you need to have custom configuration for the tests , copy the .config into the test project . Then in the Properties
pane set Copy to Output Directory
to Copy Always
, this will overwrite the projects config file .
来源:https://stackoverflow.com/questions/12571877/nunit-tests-looking-for-assembly-name-dll-config