This is my setup:
/
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
I wrote Unit Tests in the Test project that test the functionality of the Core project. All of the projects use log4net, all of them are configured using the respective App.config or Web.config files using
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
in their AssemblyInfo.cs.
The projects are built using NAnt into a build directory.
When I run the Unit Tests from Visual Studio (2010 Professional), everything works fine.
But when I try to execute MSTest directly
MSTest.exe /resultsfile:TestResults.trx /noisolation /testcontainer:build\test.dll
All test cases fail with the following error:
log4net:ERROR Failed to find configuration section 'log4net' in the application's .config file
This confuses me, because the test.dll.config file most definitely contains the log4net configuration section.
The folder created by MSTest also contains the config file:
/flopes_MyMachine 2015-10-08 08_48_59/Out/
Core.dll
test.dll
test.dll.config
log4net.dll
It appears to me that maybe MSTest is using a wrong configuration file or doesnt find the configuration file of the test.dll? Does that even make sense? Is there a way to tell MSTest which config file to use?
I did a small test output to see what configuration file is loaded, and it added even more mystery, because apparently the configuration file that was loaded is:
D:\Programme\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe.Config
How is this possible? Why does MSTest not just load the configuration file that is right beside the test.dll? How does this make sense?
I would have a look at this question and answer: MSTest.exe not finding app.config
Which states that you should create a test run configuration which includes the .config as a deployment item.
Also check if the config being used is the correct one; ways of finding active config-file:
// Get the user-config:
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath
// Simple approach
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile? Is it the correct .config
Checking a couple of things with @florianpeschka led us to believe that the problem is the noisolation-flag. And that is a bit weird, since noisolation basically controls the creation of separate sandboxes for the test-instances, but maybe the creation of separate processes is needed to use a "dynamic" and non-hardcoded config for ms-test.
So in short, do not use the noisolation-flag and everything works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With