Just Code‎ > ‎

How to get NUnit to read the correct Web.config when working with Web or WCF projects

posted Sep 30, 2009, 4:16 AM by Peter Henell   [ updated Sep 30, 2009, 4:19 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.
Published Thursday, June 07, 2007 5:51 PM by Tomek Filed under: asp.net nunit web.config postbuild events

Original Post: http://pfefferkorn.net/CS07/blogs/tomek/archive/2007/06/07/setup-web-config-with-nunit-project.aspx

Comments