DeploymentItem does not work with TestInitialze ()

I need to copy some directories / files for MS Unit test, and I have this code.

[TestInitialize()] [DeploymentItem("\\library", "library")] public void Initialize() { .... } 

The problem is that the directory / files are not copied using [TestInitialize()] , I needed to use the following:

 [TestMethod] [DeploymentItem("\\library", "library")] public void AddInt16() { ... } 

Should I use DeploymentItem only with [TestMethod] ? If not, what's wrong with my code?

+4
source share
2 answers

You can use it at the method or class level:

 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public sealed class DeploymentItemAttribute : Attribute 

Thus, a good workaround, provided that TestInitialize didn't pick it up, is to move the DeploymentItem to your class.

+10
source

Define the deployment item at the class level or in the .testrunconfig file.

+1
source

Source: https://habr.com/ru/post/1396539/


All Articles