There's an extra step you have to take when you write a unit-test for a method that reads a config-setting.
Assuming you have set up a separate test project, it will look for the config file in the test project directory.
We could simply add an app.config here, but then we would have to manage two separate files..... which is evil!
Somehow, we need to reference the original app.config.
You can achieve this by modifying the configuration settings for the currently active testrun.
Open the *.testrunconfig file. This can be done in two ways:
- it's listed under the "Solution items" in your Solution Explorer
- from the Test menu, select "Edit test run configurations"
In the Deployment tab, select the app.config file of the actual project. The files listed here will be copied to the test project directory before running your tests.
caveat: when this doesn't work, set the "Copy to output directory" property of the config file to "Copy always"