VS 单元测试框架中的单元测试模板在哪里?
我对在 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 模板附近)。 在哪里更改此模板?
I am increasingly annoyed by the unnecessarily verbose template that is used when I create a new unit test in Visual Studio (using the default, included unit testing framework). Instead of
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;
}
}
I'd like to have simply
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext { get; set; }
If I need a constructor I'll add one, and the same goes for special getters and setters. I'd also like to remove the sample TestMethod that is included - I still need to rename it, so I can just as well write my own from scratch.
I have looked for the template used for creating these test files, but not been able to find it (I looked mostly around in the neighborhood of the T4 templates used for controllers and views). Where do I change this template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Visual Studio 的所有项目模板都从此目录运行:
当然,c:\Program 文件可能会根据您的安装选项而改变。 我认为测试模板位于此处:
作为 UnitTestWizard.zip。
看起来好像 zip 中的文件是一个 xml 文件,当您打开它时,它表明它正在运行一个 dll,以便在运行时可能使用代码 dom 生成测试文件。
您可以查看 T4 模板,或者编写一个 VS 插件来完成这个最小设置,编写起来不会花费很长时间。
All of the item templates for visual studio are run from this directory:
Of course c:\Program files may change depending on your installation options. I think the test template is located here:
As UnitTestWizard.zip.
It looks as though the file within the zip is an xml file which when you open it points at the fact that it is running a dll to generate the test file at runtime probably using code dom.
You could take a look at T4 Templating for this or writing a VS add-in to do this minimum setup it wouldn't take long to write.
您想要的书是 Keyvan Nayyeri 所著的“专业 Visual Studio 扩展性”。 这是一本优秀的书,涵盖了 Visual Studio 可扩展性 (VSX) 的整个范围,从宏到 VS 包。
请务必查看 MSDN 上的 Visual Studio 可扩展性开发人员中心。 另外,我建议您下载并安装 Visual Studio 2008 SDK。 那里有一些非常好的示例,并附有源代码。
The book you want is "Professional Visual Studio Extensibility" by Keyvan Nayyeri. It's an excellent book, and covers the entire breadth of Visual Studio Extensibility (VSX), from macros up to VSpackages.
Be sure to look at the Visual Studio Extensibility Developer Center on MSDN. Also, I recommend you download and install the Visual Studio 2008 SDK. There are some very good examples there, complete with source code.