How can I get “Copy to Output Directory” to work w

2019-01-16 02:33发布

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条回答
Explosion°爆炸
2楼-- · 2019-01-16 03:14

In Visual Studio 2012 you don't need a DeploymentItem attribute for the simple case. See my answer here

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-16 03:19

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.

查看更多
混吃等死
4楼-- · 2019-01-16 03:19

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

查看更多
三岁会撩人
5楼-- · 2019-01-16 03:22

I had a similar problem but mine had to do with pointing to the TraceAndTestImpact.testsettings file instead of the Local.testsettings file. You can change from one to the other under the Test/Select Active Test Settings menu.

查看更多
仙女界的扛把子
6楼-- · 2019-01-16 03:23

All three answers are correct, depending on your needs.

Adding files to deploy in the .testrunconfig (.testsettings in VS2010) will copy all of those files to every test output folder, even for unrelated tests run in isolation. If you run one test, all the test data files listed in the deployment section of .testssettings will be copied to the test output folder.

In my tests I need to copy an expected XML file to the test output folder to compare with the actual test output XML. I use the DeploymentItem attribute to only copy the XML file related to the test(s) being run. In VS2010 I had to enable deployment in the .testsettings file (but not add any paths) and then reference the XML file path relative to the TestProject in the DeploymentItem.

Hope this helps.

查看更多
Anthone
7楼-- · 2019-01-16 03:23

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.

查看更多
登录 后发表回答