5

Is there a way to preserve folder structure with MSTEST deployment?

I have a situation with some existing code where I have .config files in a subfolder (called "Configuration"). I can specify this folder using MSTEST deployment but, in it's infinite wisdom, MSTEST just copies the files from this folder to the run folder (TestResult\\Out), i.e. it does not create a subfolder called Configuration. This royally screws up the code and it fails. I don't really want to have to start using complicated pre-test scripts to create folders etc.

Any ideas gratefully received.

Matt

Matt Cotton
  • 732
  • 9
  • 23

4 Answers4

2

I think I had the same problem...

My tests used a folder called xsd and I wanted to deploy the folder to the test \OUT directory. When I did this, the files inside the xsd folder were copied to the test \OUT directory, but I wanted the folder xsd into the test \OUT directory...

To solve this I read this. (Wayback machine has an archive of this page here)

Macha
  • 14,366
  • 14
  • 57
  • 69
Jorge
  • 59
  • 1
  • 7
  • You, my friend, are godlike. Be sure to restart VS2010 , otherwise it won't pick up your changes. – Malachi Apr 23 '12 at 18:46
  • Also, it appears you need at least one file in the directory otherwise MSTest won't pick it up – Malachi Apr 23 '12 at 19:08
  • 2
    Please dont just provide a link to a solution. Briefly explain what the solution is incase the link goes down such as in this case. – Festivejelly Oct 20 '15 at 09:47
  • Just adding the solution here (taken from the Wayback machine): In the testsettings file: Note that the back slash at the end of the file name attribute value is essential as is the “outputDirectory” attribute for this to work. – MichaelEr Nov 25 '19 at 13:42
1

If you're using the DeploymentItem attribute, it takes a second argument for the name of the directory to copy the files into. If you use the same name as your folder it preserves everything.

To use your test case you'd do:

[DeploymentItem("Configuration", "Configuration")]
class TestClass
....

and it would work.

Malcolm
  • 1,239
  • 1
  • 14
  • 25
0

In Visual Studio 2012 the output directory is the working directory which means that the DeploymentItem attribute isn't needed for the general case (where you don't have specific per-test or per-class deployment items). You can simply click Project | Show All Files and include the subfolder and files in Visual Studio with the 'Copy Always' or 'Copy if newer' attribute to your project and the files will be copied to your output directory with hierarchy intact. The same applies when running vstest.console.exe from the command line.

See here for more information about Deployment Items in Visual Studio 2012.

acarlon
  • 16,764
  • 7
  • 75
  • 94
0

Yes, you can. read the article Do MSTest deployment items only work when present in the project test settings file?

It explains how to map deployment items.

Community
  • 1
  • 1
Sriwantha Attanayake
  • 7,694
  • 5
  • 42
  • 44