If you are looking to deploy the XML file with your tests, you have a few options:
Embedded Content
You can embed the Xml file as content within the assembly.
- Add the file to your test project. In the context of this example, the file is located at the root of the project.
- Change the properties of the file to be an Embedded Resource.
- During the test you can get access to the file as a stream by using the get manifest resource.
Example:
[TestMethod]
public void GetTheFileFromTheAssembly()
{
Stream fileStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("MyNamespace.File.xml");
var xmlDoc = new XmlDocument();
xmlDoc.Load(fileStream);
Assert.IsNotNull( xmlDoc.InnerXml );
}
DeploymentItemAttribute
You can annotate the test method or class with a [DeploymentItemAttribute]. The file path is relative to the solution.
[DeploymentItem("file.xml")] // file is at the root of the solution
[TestMethod]
public void GetTheFileDeployedWithTheTest()
{
var xmlDoc = new XmlDocument();
xmlDoc.Load("file.xml");
Assert.IsNotNull(xmlDoc.InnerXml);
}
Test Settings
You can deploy individual files or entire directories using the Deployment configuration inside the Test Settings file. (Tests -> Edit Settings -> Filename.testsettings)
