14

Here is the problem:
1. Create a TestProject in your Visual Studio solution.
2. Open the .testrunconfig file and under the 'deployment' menu item, select the 'Enable Deployment' checkbox.
3. Now click on 'Add Directory...' button and add a folder which has some files in it.
4. Run the test project (use a dummy test).

Ok, now go check the TestResults folder: You will see that all the files got directly copied (to the top level)- the folder itself is not copied (with the files under them). This messes up my paths during testing. Can anybody tell how to get the folder copied instead of just the files underneath ?

Thanks.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
DeeStackOverflow
  • 2,741
  • 4
  • 23
  • 23
  • I just did like you said, and unchecked 'Enable Deployment' in the test settings to have it stop creating the new dir and use the existing bin\Debug dir instead. Much better and less buggy! – goku_da_master Jul 06 '16 at 20:59

4 Answers4

17

Use the [DeploymentItem] attribute on the test classes that use it. You can specify a directory:

[TestClass]
[DeploymentItem("blahblah\\myDirectory", "myDirectory")]
public class MyTest
{

}

Note:

  • DeploymentItem is very slow when starting the tests. It seems to copy 2 files per second.
  • You can specify the attribute on a test base class. But it does not always work if you have more than one test project.
  • You can probably specify it on a TestClass that has a method marked with [AssemblyInitialize]. Then you have only to provide it once. Not sure, you have to try.
  • The source directory is relative to the solution location. This is hardly documented.
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • 2
    Hmm. This requires hardcoding within the test fixture class rather than the .testrunconfig file. I decided to set 'Enable Deployment' unchecked and am doing everything within the bin\Debug folder where I have all data files set to 'Copy Always'. Does the job. Thanks for the information though ! – DeeStackOverflow Apr 16 '09 at 17:31
  • 2
    It's straight forward to turn off "deployment". But you should consider the risk having files in bin\debug from older builds. Your tests could only run/fail on your machine. So clean up bin\debug before running tests every now and then. – Stefan Steinegger Apr 17 '09 at 06:42
  • same problem with dirty files can happen with running code as well as tests! – Matt Connolly Aug 30 '12 at 00:52
11

Open the .testsettings file in notepad. Now, you should see that for every folder to copy

<DeploymentItem filename="FolderName\" />

Change this to

<DeploymentItem filename="FolderName\" outputDirectory="FolderName\" /> 
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Jaikishan Jalan
  • 111
  • 1
  • 2
  • 1
    This is exactly what I needed, thank you. I needed to restart Visual Studio for it to take effect. – Ciaran Apr 18 '12 at 13:42
  • Variation on the above answer. I had filename="FolderName\SubfolderName\" which needed to be converted to filename="SubfolderName\" outputDirectory="SubfolderName\" in order to work correctly – Carl Onager Sep 13 '12 at 14:36
  • Thank you it helps. Need the same hack in VS2013 as well. I wonder why do you need to use text editor to specify outputDirectory ! Microsoft should fix the edit testsettings dialog. Didn't liked the accepted answer, this one is more cleaner. – lame_coder Jan 14 '15 at 18:35
0

The other option you have is to create another folder beneath the original folder, and then that folder will be deployed to the out directory. For example you can have this structure:

TestFolder/

TestFolder/TestDeployment/

And then in the testrunconfig you still select the TestFolder folder and the TestDeployment folder will be deployed to the out directory.

0

I just had this problem too today. I solved it by adding a folder called "deployment_files" in the project that contained the required folder. Then I put the required folder into the "deployment_files" folder. THEN, I opened the LocalTestRun.testrunconfig file under the "Solution Items" folder in the Solution Explorer. Went to the "Deployment" panel in the testrunconfig property window. Added the "deployment_files" directory to the deployment and voila. The folder within that was copied to the test results Out folder.

Joey Guerra
  • 596
  • 6
  • 11