I'm currently maintaining an "old" system written in C#.net, removing some obsolete features and doing some refactoring. Thanks god, the previous guy wrote some unit tests (MSTests). I quite comfortable with JUnit tests, but didn't do yet much with MSTests.

The test methods have a DeploymentItem attribute, specifying a text file which is parsed by the business logic method that is being tested and a 2nd DeploymentItem where just a path has been specified containing a bunch of TIF files that have to be deployed too.

[TestMethod()]
[DeploymentItem(@"files\valid\valid_entries.txt")]
[DeploymentItem(@"files\tif\")]
public void ExistsTifTest()
{
   ...
}

The tests worked before, but now I had to change the names of the TIF files contained in the \files\tif directory. According to a rule, the TIF filenames have to match a certain pattern which is also checked by the ExistsTifTest() method. Now I had to change the filenames in order to adapt them to the new requirements and suddently the TIF files are no more being deployed as before.

Can someone give me a hint why this happens or what may be the cause? The same thing happens also if I add a new text-file say "my2ndTest.txt" beside the "valid_entries.txt" in the \files\valid\ directory with the according DeploymentItem attribute on the test method. The file doesn't get deployed?

I got the images now deployed by defining the deployment path directly in the testrunconfig, but I'd like to understand why these things happen or why for instance my new file "my2ndTest.txt" doesn't get deployed while the others do.


DeploymentItem is a bit of a mess.

Each file in your solution will have a "Copy To Output Folder" setting in VS.NET. You need this to be "Copy Always" (or similar) in order to get the files into the output folder.

Check that you've got this set for the new files. If you don't have this set then the files won't get copied to the output folder, and then they can't be deployed from the output folder to the folder where MSTest does it stuff.

Personally, if I have files that I need for my unit tests I've found that embedding those files as resources into an assembly, and having that assembly "unpack" itself during the tests is a more predictable way of doing things. YMMV.

note: These comments are based upon my experience with VS2010. Comments to my answer would suggest that this is not problem with VS2012. I still stand by comments that using embedded resources involves less "magic" and, for me, makes the "arrange" stage of my unit tests much more explicit.


In VS2010, my Local.testsettings had the "Enable Deployment" unchecked and the DeploymentItem attribute was not working. I checked it and everything worked fine. I hope this helps!


I have also faced similar problems but i found easy 3 step solution for this:

Assuming your folder structure looks like this: SolutionFolder\ TestProjectFolder\ SubFolder\

  1. Go to "Solutions Items/Local.testsettings" > "Deployment" > Check "Enable Deployment"
  2. If you are using VS2010, make sure any files you want to deploy have their "Copy To Output Folder" property set to "Copy Always" or "Copy if Newer"
  3. Attribute your TestMethod with either one of:
    • [DeploymentItem(@"TestProjectFolder\SubFolder")] to deploy all contents of <SubFolder> to the Test Run directory
    • [DeploymentItem(@"TestProjectFolder\SubFolder", "TargetFolder")] to deploy all contents of <SubFolder> to <TargetFolder> in the Test Run directory

One final note about MSTest (at least for VS2010):

If you want the <TargetFolder> to have the same name as the <SubFolder>, using [DeploymentItem(@"SubFolder", @"SubFolder")] will fail silently as the MSTest runner hits a silly edge case. This is why you should prefix the <SubFolder> with the <TestProjectFolder> as so: [DeploymentItem(@"TestProjectFolder\SubFolder", @"SubFolder")]