Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest VS2010 - DeploymentItem copying files to different locations on different machines

I have found that DeploymentItem

[TestClass(), DeploymentItem(@"TestData\")]

is not copying my test data files to the same location when tests are built and run on different machines.

The test data files are copied to the "bin\debug" directory in the test project on my machine, but on my friend's machine they are copied to "TestResults\name_machine YY-MM-DD HH_MM_SS\Out".

The bin\debug directory on my machine can be obtained with the code:

string appDirectory = 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

and the same code will return TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out on my friends PC.

This however isn't really the problem. The problem is that the test data files I have made have a folder structure, and this folder structure is only maintained on my machine when copied to bin\debug, whereas on my friends machine only the files are added to the TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out directory. This means that tests will pass on my machine and fail on his!

Is there a way to ensure that DeploymentItem always copys to the bin\debug folder? Or a way to ensure that the folder structure will be retained when DeploymentItem copies the files to the TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out folder?

like image 351
Jack Avatar asked Nov 05 '22 12:11

Jack


1 Answers

After playing around for a while, it looks like the best way to deal with it is to ensure that for every subdirectory, you add a new DeploymentItem making sure that you specify the "outputDirectory", like so:

[TestClass(), DeploymentItem("TestData\\", "TestData"),
DeploymentItem(@"TestData\\SubDir\\", "TestData\\SubDir")]

This allows the tests to run on your machine - hope this helps someone!

like image 98
Jack Avatar answered Nov 15 '22 07:11

Jack