Monday 24 November 2014

NUnit Web.config

When using NUnit to test a web project, by default NUnit won't read the Web.config, it is only looking for a config file named TestProjectNamespace.dll.config.

We can quickly configure Visual Studio so the web.config file is copied (and renamed) from your web project to the NUnit build folder.

Add the web.config File as a Link
  1. Right click on NUnit project in Visual Studio
    Add > Existing Item
  2. Navigate to the web.config file in the web project
  3. Select the web.config file
    click on the arrow beside the Add button > Add As Link

Edit the NUnit Project File
Use a text editor to edit the NUnit project file, you will be able to find the lines where you have added the web.config file.

Change from:
    <None Include="..\Other.Project\Web.config">
      <Link>Web.config</Link>
    </None>

To:
    <None Include="..\Other.Project\Web.config">
      <Link>Namespace.dll.config</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>

This will copy the linked file and rename it so NUnit will find it.

No comments:

Post a Comment