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.



[TestMethodDeploymentItem("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

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?