Cole W
Cole W

Reputation: 15303

Using a config file in Microsoft Unit Tests

Currently for a number of my unit tests I require that some configuration be pulled from a file. Initially I thought I only needed to add Test Settings to my unit testing project and configure this in Test Settings->Deployment. I added my config file here but my unit tests were still complaining that they couldn't find this config file. Finally I found that I needed to add the [DeploymentItem("Test.config")] attribute to any of my unit test classes that needed this.

Is this how it's supposed to be done? It seems like I should not have to use the DeploymentItem attribute. Am I doing something wrong here?

Upvotes: 2

Views: 2730

Answers (2)

Chad Ferguson
Chad Ferguson

Reputation: 3091

set the config file to copy to the output directory in a post build

Upvotes: 1

Gerrie Schenck
Gerrie Schenck

Reputation: 22368

Do you mean that your code under test requires a config file? Then you can add a regular app.config to your unit tests. Well in all other cases you can use that as well.

Upvotes: 2

Related Questions