Freigeben über


Why mstest did not deploy my deployment item?

Michael has done a great post on how deployment works in mstest, so if you want to understand its working, I will strongly suggest you to go through it. In this post, I want to share the deployment item selection logic of mstest. i.e. If you have deployment items on your various test methods/test classes, then which items will be deployed and which ones will not be.

The basic idea of the selection is to use the deployment items mentioned on the test methods & corresponding classes that you have selected in your test run. For example in the below sample test project, if you are running TestMethod1, then myfile1.txt and myfile3.txt will get deployed and if you have selected both the tests, then files ..1, ..2, ..3 will get deployed. The file ..4 will never get deployed as there is no test in TestClass2.

namespace TestProject1
{
[TestClass]
[DeploymentItem("myfile3.txt")]
public class TestClass1
{

        [TestMethod]
[DeploymentItem("myfile1.txt")]
public void TestMethod1()
{
}

        [TestMethod]
[DeploymentItem("myfile2.txt")]
public void TestMethod2()
{
}
}

    [TestClass]
[DeploymentItem("myfile4.txt")]
public class TestClass2
{
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{ }
}
}