Attention: We are retiring the ASP.NET Community Blogs. Learn more >

NUnit and ConfigurationSetings AppSettings

I've had the link below for a while, and now that I want to use it, I can't make it work. I don't even seem to have access to AppSettings from the nunit-gui.exe.config.

In a [Test] ConfigurationSettings.AppSettings.Count is zero :( and I would like to test some provider type stuff that relies on custom configuration sections.

Any suggestions or good links out there?

NUnit tip for ConfigurationSetings AppSettings:
 http://weblogs.asp.net/psperanza/archive/2004/02/24/79596.aspx

3 Comments

  • Since your main program in this case is NUnit - not your own program - you can simply add whatever appsettings you have your own .config file into the NUnit .config file.



    This file should be something like C:\Program Files\NUnit 2.2\bin\nunit-gui.exe.config.



    \Steven



  • Alternative, you can use NUnit's out-of-the-box support for configuration files. If your unit tests live in foo.dll, just put a config file called foo.dll.config in the same directory as your test .dll and NUnit will load the configuration for you.

  • OK, I spent aaaaages working round this one, before it all suddenly became very simple. Given any NUnit project file, say "foo.nunit", create a file in the same folder called "foo.config". Place all your settings in there, and the applications will have them in their context. You can then link your app.config/web.config files to use the settings out of this file, thus needing maintenance in one place only.



    Personally, I have a custom written GetSetting() method in every application I write. It checks to see if the key "NUnit.Context" is true. If it is, it reads the config document manually (as XML), otherwise it uses the built in .NET classes. That way the only content in foo.config is a single key to notify the application of its context.

Comments have been disabled for this content.