2

当我在Visual Studio中创建新的单元测试时(使用默认的,包含的单元测试框架),我越来越讨厌使用不必要的冗长模板。取而代之的VS单元测试框架中的单元测试模板在哪里?

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模板附近看了大多是围绕)。我在哪里改变这个模板?

+0

我知道你的意思。我前段时间尝试过,发现测试代码是动态创建的。我最终的解决方案是去nUnit。 – Robert 2009-06-02 19:18:37

回答

2

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

C:\ Program Files文件\微软的Visual Studio 9.0 \ Common7 \ IDE \的ItemTemplate

当然的C: \程序文件可能会根据您的安装选项而改变。我认为测试模板位置为:

C:\ Program Files文件\微软的Visual Studio 9.0 \ Common7 \ IDE \的ItemTemplate \ CSHARP \ 1033

由于UnitTestWizard.zip。

看起来好像在zip中的文件是当你打开它指向它正在运行一个dll在运行时生成的测试文件可能使用代码DOM事实的XML文件。

你可以看看T4模板这个或写一个VS插件做到这一点花不了多长时间写这个最小建立。

+0

你有关于我如何做这件事的信息的任何链接? – 2009-06-08 13:42:49