Unit Testing - Deploy Files & Folders (Microsoft Visual Studio)
Scenario: I have a test that needs a file deployed inside a folder (e.g. - DeploymentItems\ControlsMetaData.xml)
You can use the DeploymentItem attribute with the 2 parameters overload and specify the directory (folder) you would like the test file to be deployed in.
[TestMethod, DeploymentItem("DeploymentItems\\ControlsMetaData.xml", "DeploymentItems")]
public void DeployFileAndContainingFolder()
{
// Arrange
// Act
var xmlFiles =
UXStandardsViewModel.GetFilesByExtension(
Path.Combine(TestContext.TestDeploymentDir, "DeploymentItems"), ".xml");
// Assert
Assert.AreEqual(1, xmlFiles.Count());
}
The test above, gets all files with extension “.xml” at “DeploymentItems\ControlsMetaData.xml”
The folder above is the Test output directory.
Comments
Post a Comment