How can I get "Copy to Output Directory" to work with Unit Tests?

Viewed 73886

When I build a unit test project before the tests are executed the test output is copied to a TestResults folder and then the tests are executed. The issue I'm having is that not all the files in the Debug/bin directory are copied to the TestResults project.

How can I get a file that is copied to the Debug/bin directory to also be copied to the TestResults folder?

11 Answers

The standard way to do this is by specifying the deployment items in the .testrunconfig file, which can be accessed via the Edit Test Run Configurations item in the Visual Studio Test menu or in the Solution Items folder.

Try out the Post-Build event command line from within Visual Studio (if you are using that IDE).

The accepted answer is correct and so are most of the other answers. However, over the years I have found that the Deploment system of Visual Studio Unit Tests using DeploymentAttribtue and Copy to Output to be cumbersome if you have a large number of data files. I have found that keeping the files in their original location worked better.

Full details in my other answer here. https://stackoverflow.com/a/53004985/2989655

Hope this helps.

Related