【问题标题】:How can I enforce the unit tests to use the main applications root path but not the TestResults?如何强制单元测试使用主应用程序根路径而不是 TestResults?
【发布时间】:2012-07-03 11:57:10
【问题描述】:

我使用 Microsoft Visual Studio 测试工具程序集进行单元测试。

从我的一个单元测试中,我测试了一个加载文本文件的类。

问题是,在单元测试运行的时候,becoms的根目录:

C:\Users\Foo\Documents\Visual Studio 2010\Projects\MyProject\TestResults\Foo_HisComputer 2012-07-03 13_50_45\Out

这就是找不到文件的原因。

如何强制单元测试运行时使用主应用程序的根路径,而不是它在每次单元测试运行后生成的 TestResults 文件夹?

【问题讨论】:

    标签: c# .net unit-testing io


    【解决方案1】:

    您可以将文本文件添加到输出中:

    [TestClass]
    [DeploymentItem("textfile.txt")]
    public class BaseUnitTest
    {
    }
    

    需要在项目中设置文本文件,并复制到输出文件夹中。

    否则,也许这个链接可以帮助你:

    http://msdn.microsoft.com/en-us/library/ms243187.aspx

    【讨论】:

    • 复制一个文件夹怎么样?我在一个名为 Templates 的文件夹中有很多文件。
    • 只放文件夹名而不是文件名。 [部署项(“我的文件夹”)]
    • 我找到它并这样做了:[DeploymentItem("Folder\\", "Folder\\")]
    猜你喜欢
    • 1970-01-01
    • 2011-09-19
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    相关资源
    最近更新 更多