My unit test project uses a app.config file that has external source references to other config files located in my “configuration” folder. My configuration folder is a sub folder of the unit test project. When the unit test runs, I need to deploy this folder to the TestResults/Out folder so the app.config can be properly loaded during test execution.
Here’s the easiest way to accomplish deploying folders to the TestResults folder:
- Right click on the .testrunconfig file in your solution explorer. For me, its LocalTestRun.testrunconfig.
- Select Open With and select XML editor
- Add a deployment item, specifying the relative path as the file name and an outputdirectory value of the directory name. In my example, I want to deploy everything in the configuration directory to a folder called configuration in the testrun folder, so I’ve added the following entry:
<Deployment>
<DeploymentItem filename="Services\Identity\Claim\ClaimService.Test\configuration\" outputDirectory="configuration\" />
</Deployment>
Now when my tests execution, Visual Studio copies over all my configuration file entries and is able to load the app.config file successfully.