Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeploymentItem doesn't 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 with [TestInitialize()], I needed to use as follows:

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

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

like image 784
prosseek Avatar asked Dec 22 '22 02:12

prosseek


2 Answers

You can use it at a method or class level:

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

so, a good workaround given that its not picked up by TestInitialize is to move the DeploymentItem to your class.

like image 180
wal Avatar answered Dec 28 '22 09:12

wal


Either define the deployment item at class level or at the .testrunconfig file.

like image 35
Dror Helper Avatar answered Dec 28 '22 08:12

Dror Helper