How to get NUnit to read the correct Web.config when working with Web or WCF projects
Post date: Sep 30, 2009 11:16:48 AM
A quick and dirty way to make your web.config available in the NUnit project (Visual Studio class library). This assumes you are unit testing the web site (in Visual Studio 2005 you don't have pre/post build events for this kind of project).
- Setup post build event for the NUnit project (Right click on the project name, go to Build Events)
- If you want to see all the macros available to you, click on the Edit Post-build button, then Macros
- Put the following command into the post build event textbox: copy /Y "[Physical path to the project]\Web.config" "$(TargetDir)$(TargetFileName).config"
- This will copy and rename the web.config file from your project into the NUnit project's bin directory. From now on you can access all the settings in the web.config file from within your unit tests.