NUnit Testing and Custom .NET Configuration File

I got hit with this problem, not so long ago.  I was testing a project I was making and in some of the tests this involved the retrieval of settings from the configuration file.  I created an App.config file for the assembly, and went onto to create the tests!  What happened was simply NUnit could not see the App.Config of the assembly it was testing.

After some routing about online, I found the solution, which is actually quite simple.  For testing purposes simply create a duplicate of your App.config file and give it the same name as your assembly, e.g. YourAssemblyName.config.  Run your tests again and you can now use code like:

YourSection section = (YourSection)ConfigurationManager.GetSection("YourSection");

Hope this is of use to some people.

Cheers,

Andrew

Published Thursday, April 24, 2008 12:42 PM by REA_ANDREW
Filed under: ,

Comments

# re: NUnit Testing and Custom .NET Configuration File

Thursday, April 24, 2008 1:15 PM by Refactored

Your App.config should be getting copied into the appropriate bin folder and renamed automatically. Alternatively, what you should probably look into is using a mocking framework (such as Typemock) to completely mock the config dependencies whenever possible.

Leave a Comment

(required) 
(required) 
(optional)
(required)