c# - DeploymentItem 未部署文件

标签 c# unit-testing visual-studio-2012 vs-unit-testing-framework deploymentitem

我正在使用 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 中找到了两种可能的解决方案:

  1. 将部署文件的“复制到输出文件夹”属性设置为“始终复制”(参见 Problems with DeploymentItem attribute)
  2. 检查 Local.testsettings 文件中的“启用部署”设置(参见 Problems with DeploymentItem attribute)

希望这对您有所帮助。

关于c# - DeploymentItem 未部署文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16787003/

相关文章:

.net - Visual Studio 2012 和 Resharper 的 goto 实现

c# - 使用性能计数器监视特定端口

unit-testing - 是否有一个MSTest等效于NUnit的显式属性?

c# - 开关语句示例

java - 使用 mockito 对构造函数进行单元测试

unit-testing - Spock 数据驱动测试,使用类来测试 "instanceof"断言

sql - 如何使用 Visual Studio Express 2013 从 sql-server 2008 导入数据到 excel

c# - 绘制树的算法,其中节点可以附加到深度大于自身 + 1 的其他节点

c# - 如果线程正在更改,则缓存 Controller 操作

c# - 如何将 jquery 的 UI 自动完成与 ASP.NET 和外部数据源一起使用?