Matt Cotton
Matt Cotton

Reputation: 772

MSTEST folder deployment question

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

Upvotes: 5

Views: 5145

Answers (4)

Jorge
Jorge

Reputation: 59

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)

Upvotes: 2

acarlon
acarlon

Reputation: 17272

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.

Upvotes: 0

Malcolm
Malcolm

Reputation: 1259

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.

Upvotes: 1

Sriwantha Attanayake
Sriwantha Attanayake

Reputation: 7908

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.

Upvotes: 0

Related Questions