Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a Visual Studio Unit Testing feature for this: <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute%28VS.90%29.aspx" rel="noreferrer">DeploymentItemAttribute</a></p> <p>I use this feature to copy all xml files in a given project folder to the unit test output folder, before testing if all required files are present.</p> <p>You can use this attribute with your unit tests to copy specific files from the Project folder (or anywhere else) to the Unit Test output folder. Like so:</p> <pre><code>[TestMethod()] [DeploymentItem("MyProjectFolder\\SomeDataFolder\\somefile.txt", "SomeOutputSubdirectory")] public void FindResourcefile_Test() { string fileName = "SomeOutputSubdirectory\\somefile.txt"; Assert.IsTrue(System.IO.File.Exists(fileName)); } </code></pre> <p>You can also copy the contents of whole folders:</p> <pre><code>[TestMethod()] [DeploymentItem("MyProjectFolder\\SomeDataFolder\\", "SomeOutputSubdirectory")] public void FindResourcefile_Test() { string fileName = "SomeOutputSubdirectory\\someOtherFile.txt"; Assert.IsTrue(System.IO.File.Exists(fileName)); } </code></pre> <p>The first parameter is the source, the second the destination folder. The source is relative to your solution folder (so you can access the Unit Test project of the project being tested) and the destination is relative to the output folder of the unit test assembly.</p> <p><strong>UPDATE:</strong></p> <p>You need to enable Deployment in the Test Settings for this to work. This MSDN page explains how (it's real easy): <a href="http://msdn.microsoft.com/en-us/library/ms182475(v=vs.90).aspx#EnableDisableDeploy" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms182475(v=vs.90).aspx#EnableDisableDeploy</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload