Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MSTest DeploymentItem fail when running all tests in solution?

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?

like image 913
k3b Avatar asked May 09 '11 16:05

k3b


1 Answers

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.

  1. Edit your .testsettings in the Solution Items folder
  2. Select the Deployment category
  3. Check the "Enable deployment" option
  4. 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 TestMethods). 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 the DeploymentItem 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 DeploymentItems completely and try your two test runs (from project and from solution) and see what results you get.


In Case Deployment Items are Working Despite the Documentation

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")]
like image 57
Anthony Mastrean Avatar answered Oct 16 '22 09:10

Anthony Mastrean