C# - reading an app.config in MSTest / Unit tests

1.2k Views Asked by At

I'm trying to work out how to (and at the same time best practice) use an app.config file in unit tests (MSTest specifically).

So I have the actual project then a separate project. the actual project has an app.config - and it seems that the unit tests are using that file and not ones I am trying to specify.

I have tried the following:

  1. Putting a copy of app.config in the root of the test project, removing some key config sections that are used within the code so thus should cause exceptions and failures - this doesn't seem to work

  2. using

    [DeploymentItem("app.config")]
    

Which I believe picks up the app.config from the test project root and deploys that?? Strangely, I also tried to change the path to

[DeploymentItem("Data\\app.config")]

Which is a directory I use to load other deployment items - however it complains that it cannot find the app.config.

What am I doing wrong here - and also am I doing it the right way (assuming I am missing something simple). I basically want a separate app.config where I can use specific test settings rather than use the real app.config copied or referenced.

0

There are 0 best solutions below