【问题标题】:Where are the Unit Test templates in the VS Unit Testing Framework?VS 单元测试框架中的单元测试模板在哪里?
【发布时间】:2009-06-02 19:14:23
【问题描述】:

当我在 Visual Studio 中创建一个新的单元测试(使用默认的、包含的单元测试框架)时使用的不必要的冗长模板让我越来越恼火。而不是

public ImportModelStateTest()
{
    //
    // TODO: Add constructor logic here
    //
}

private TestContext testContextInstance;

/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
    get
    {
        return testContextInstance;
    }
    set
    {
        testContextInstance = value;
    }
}

我想要简单的

/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext { get; set; }

如果我需要一个构造函数,我会添加一个,特殊的 getter 和 setter 也是如此。我还想删除包含的示例 TestMethod - 我仍然需要重命名它,所以我也可以从头开始编写自己的。

我一直在寻找用于创建这些测试文件的模板,但没有找到(我主要在用于控制器和视图的 T4 模板附近四处寻找)。在哪里更改此模板?

【问题讨论】:

  • 我知道你的意思。我前段时间试过这个,发现测试代码是动态创建的。我最终的解决方案是使用 nUnit。

标签: visual-studio-2008 unit-testing t4 visual-studio-templates


【解决方案1】:

Visual Studio 的所有项目模板都是从这个目录运行的:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates

当然 c:\Program 文件可能会根据您的安装选项而改变。我认为测试模板位于此处:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\1033

作为 UnitTestWizard.zip。

看起来好像 zip 中的文件是一个 xml 文件,当您打开它时,它指出它正在运行一个 dll 以在运行时生成测试文件,可能使用代码 dom。

您可以为此查看 T4 模板或编写一个 VS 插件来执行此最低设置,它不会花费很长时间来编写。

【讨论】:

  • 你有任何链接到我如何做到这一点的信息吗?
  • 尝试查看 Visual Studio 可扩展性或 vsx。 wrox 出版商有一本关于视觉工作室可扩展性的书,这是一本好书。
【解决方案2】:

您想要的书是 Keyvan Nayyeri 的“Professional Visual Studio Extensibility”。这是一本很棒的书,涵盖了 Visual Studio 可扩展性 (VSX) 的整个广度,从宏到 VS 包。

请务必查看 MSDN 上的 Visual Studio Extensibility Developer Center。另外,我建议您下载并安装Visual Studio 2008 SDK。那里有一些非常好的例子,并附有源代码。

【讨论】:

    猜你喜欢
    • 2017-08-10
    • 1970-01-01
    • 2011-01-16
    • 2010-09-10
    • 2023-04-10
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多