Can you share a web config from an ASP.NET application with a unit testing project

242 views Asked by At

I have a complete ASP.NET project and am now trying to use automatic testing methods to test the code.

So, I have calls to methods which use configurationManager to call settings from Web.config for things like API keys etc..

My question is, it possible to synchronise my app.config for my test project and my web.config, so that if I update either one of them it takes effect on both projects, or will I have to do something different?

I have currently just copied what I need from the web.config, but because I work for a website we always have changing variables and I can't guarantee that if we change one that my colleagues will remember to update the corresponding key in both projects.

1

There are 1 answers

0
Greg Trevellick On

In the unit test project properties, you can add a pre-build step to copy the main web.config to the unit test project, overwriting the existing unit test project config file. This will do the same as you do now manually, but gaurantees the two config files will be in sync.

Alternatively, and perhaps better, delete the existing unit test config file (and exclude from the project) the click 'Add Existing Item' within the unit test project, choose the main project config file, and select 'Add As Link' instead of 'Add' (click the right hand edge of the 'add' button to achieve this). There will only be one config file on your disc, but both projects will use it.