我正在使用 MS 单元测试框架
来测试我的 C# 库。我必须打开一个我正在使用 DeploymentItem 属性
部署的文件。但是它没有将文件部署到测试部署目录。
在我的单元测试项目中,我创建了一个文件夹 TestFile
在这个文件夹中有多个文件,比如 a.txt,b.txt。
现在,在我的单元测试类中,我添加了 DeploymentItem 属性。但是文件没有被复制。
这是我的代码。
[TestClass]
[DeploymentItem("TestFile")]
public class CustomLibraryTest
{
public TestContext TestContext { get; set; }
[TestMethod]
[DeploymentItem(@"TestFiles\a.txt")] // THis should deploy a.txt to test deployment directory
{
var path = TestContext.TestDeploymentDir + "a.txt";
// Now when I debug this unit-test, and open path in explorer,
// a.txt is not present in "TestResults\Deploy_fhafeez 2013-05-28 13_02_37\Out" folder
}
}
我做错了什么?
最佳答案
我在 this thread 中找到了两种可能的解决方案:
- 将部署文件的“复制到输出文件夹”属性设置为“始终复制”(参见 Problems with DeploymentItem attribute)
- 检查 Local.testsettings 文件中的“启用部署”设置(参见 Problems with DeploymentItem attribute)
希望这对您有所帮助。
关于c# - DeploymentItem 未部署文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16787003/