Add content file to installation output directory

I am new to unit testing in visual studio and I want to load a physical XML file. This file is in the unit test project as Content, and it is copied to the output directory.

So, when I compile the project, the xml file is in the output directory. But when I run the test, a new directory is created with all the dependent DLLs, but the xml file is not copied.

Xml content is required to run the test. I am executing this code to get the path to the Xml file in the runtime folder:

private static string GetXmlFullName() { // GetApplicationPath use the current DLL to find the physical path // of the current application string executeDirectory = AssemblyHelper.GetApplicationPath(); return Path.Combine(executeDirectory, "content.xml"); } 

The exception is:

 System.IO.DirectoryNotFoundException: 'd:\***\solutiondirectory\testresults\*** 2012-06-13 17_59_53\out\content.xml'. 

How to add this file to the runtime folder?

Thanks in advance. (and sorry for my english ...)

+8
c # unit-testing visual-studio
source share
1 answer

You need to put DeploymentItemAttribute in a test class.

For example, to include all files in a data folder

 [TestClass()] [DeploymentItem("Data")] public class MyTestClass { ... } 
+6
source share

All Articles