0

When working with MSTest, how to deploy a test data folder to the TestResults directory?

In my UnitTests project, I have a TestData folder containing some xml files as test data.

I've updated the ci.testrunconfig so that it deploys the TestData folder when the Test runs:

<Deployment>
    <DeploymentItem filename="TestData" outputDirectory="CustomFolder/TestData" />    
  </Deployment>

But it doesn't deploy the folder.

How to fix it?

I could deploy the files by setting the "Copy to Output Directory" to "Copy Always" for a particular file for example but I'd like to avoid this approach as I won't have control over where the files/folder will be deployed.

Ben Aaronson
  • 6,955
  • 2
  • 23
  • 38
The Light
  • 26,341
  • 62
  • 176
  • 258

2 Answers2

0

You need to use DeploymentItem tag. You can do it on class or for a specific unit test. In your Test project add directory and files which you need to deploy (For example MyFiles).

In your test class ass DeploymentItem and give your directory name to it.

[TestClass]
[DeploymentItem("MyFiles")]
public class MyClassTest
{
    [TestMethod]
    public SomeMethodTest()
    {
        // Your unit test.
    }

    [TestMethod]
    [DeploymentItem("MyFiles")]
    public AnotherMethodTest()
    {
        // Your unit test.
    }
}
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
0

EDITED I've missed that you work with VS2005-VS2008 since you use .testrunconfig which in VS2010 and later is .testsettings.

Anyway, I've just struggled with the very similar problem. That's what I've found. You can deploy folder to TestResults directory in one of the following ways:

  1. Set enable deployment checkbox in .testrunconfig or .testsettings. Select folder that you need to deploy. Thing is folder will not be deployed, but folder contents will be deployed(if folder is empty then nothing will be deployed) to TestResults directory. Just in root of TestResults directory. If you need to deploy folder and folder content then there is option No 2

  2. Again, Set enable deployment checkbox in .testrunconfig or .testsettings. Use [DeploymentItem(pathOrigin, pathDest)] attribute. PathOrigin can be absolute or relative path. Relative path is relative to RelativePathRoot setting found in the .testrunconfig or .testsetting file. RelativePathRoot is your solution folder by default, so use Projectname/DirectoryName to deploy directory to TestResults. If MSTest can't find directory(or file) it tries to find it in bin folder of your TestProject.

Also after all experiments with testsettings you need to manually refresh TestView window

nikita
  • 2,737
  • 2
  • 20
  • 26