I have a Visual Studio 2010 solution with several MSTest projects. One of the test projects needs a file in a specific directory to run.
[TestClass]
[DeploymentItem("ReportEngine.config")]
[DeploymentItem("Report Files", "Report Files")]
public class MyReportTests { }
These tests pass when I run only the tests in this project (or test class). The report files are copied to the test execution directory. These tests fail when I run all the tests in the solution. The report files are not copied to the test execution directory.
Why is there a difference and how do I make the two runs deploy the same items?
I originally gave you instructions to ensure that Deployment was enabled in your test settings. You said that it was.
Make sure that you have deployment enabled for the test run.
- Edit your
.testsettings
in the Solution Items folder- Select the Deployment category
- Check the "Enable deployment" option
- Click "Apply" and "Close"
However, since last time I answered, I learned that the DeploymentItem
attribute only targets methods (and then, it seems only works on TestMethod
s). It could never have worked the way you have it decorating a class
. I also noticed your comment on your question (edited for grammar)
Yes, the items are set to
Copy Always
, otherwise theDeploymentItem
in the project test run wouldn't work.
There's a lot of discussion whether this is necessary or not to make DeploymentItem
work. I suspect that something we haven't identified yet is making tests pass when running them from the project. Please remove the DeploymentItem
s completely and try your two test runs (from project and from solution) and see what results you get.
Make sure that ReportEngine.config
and ReportFiles\
are where you and MSTest expect them to be. Relative file paths are resolved starting at the "RelativeRootPath". By default, that's the $(SolutionDir)
. Unless you override it in the testsettings
. Please check on that.
But, by default
[DeploymentItem("ReportEngine.config")]
is expanded to something like
[DeploymentItem("$(SolutionDir)\ReportEngine.config")]
then, for example, to
[DeploymentItem("D:\code\my-project\ReportEngine.config")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With