Paul Speranza's .Net Life

Life with .Net

NUnit tip for ConfigurationSetings.AppSettings

Today I had to unit test a dll that will read the web.config file from my web app. Here is the setup

     MyUnitTester

           TestSettings (Tests GetSettingsFromKey)

     MyBusinessObject

           GetSettingsFromKey

I never had to do this before so I read the NUnit PDF and it actually turned out to be quite simple.

  • Copy the web.config file that you will read into the bin\debug directory of the test project.
  • Look for a file with the .nunit extension (should be the same name as the test project's dll)
  • Rename the web.config file to the same name as the nunit file but change .nunit to .config.
  • Run your tests.

 

 

 

Comments

TrackBack said:

# May 31, 2004 10:57 PM

Jeff said:

Didn't work for me. In fact, I put this in a test, and it always outputs a zero:

Console.WriteLine(ConfigurationSettings.AppSettings.Count.ToString());

I'm pulling my hair out here!
# May 31, 2004 11:05 PM

Jeff said:

In the NUnit build I have, turns out the config file needs to be called <nunitproject>.nunit.config. Not what anyone really expected, but it works!
# May 31, 2004 11:27 PM

steven said:

well what worked for me is:
<projectname>.dll.config
weird!
thanks though - wouldn't have had a clue otherwise
# June 4, 2004 10:52 AM

TrackBack said:

# June 21, 2004 12:09 PM

TrackBack said:

# August 15, 2004 11:16 AM

TrackBack said:

# August 17, 2004 9:51 PM

mike bouchard said:

I'm using nunit 2.4.1 and I couldn't get a connectionstring.

After following the steps of copying my web.config to my unittest project, I had to use: <projectname>.dll.config

This thread solved my problem. Thanks!

# July 10, 2007 3:03 PM

Joe said:

Worked great - Thank you.

# August 28, 2007 1:53 PM

KelDawg said:

Thanks for the tip this helped greatly.

# November 27, 2007 7:08 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)