更改默认 MsTest 单元测试向导模板 [英] Change Default MsTest Unit Test Wizard Template

查看:20
本文介绍了更改默认 MsTest 单元测试向导模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队正在使用单元测试向导,但发现生成的 cruft 数量很烦人.有没有办法修改这个模板?

My team is using the unit test wizard, but has found the amount of cruft generated annoying. Is there anyway to modify this template?

谢谢

推荐答案

是的,你可以,在几个层面上:

Yes, you can, on several levels:

项目模板

您可以使用 Visual Studio 中的选项"菜单删除关于测试项目"和其他文件.

You can get rid of the "About Test Projects" and other files using the Options menu in Visual Studio.

转到测试工具 -> 测试项目并取消选择您不想要的选项.

Go to Test Tools -> Test Project and unselect the options you don't want.

如果这还不够,您可以在类似这样的文件夹中找到项目模板:

If that is not enough, you can find the project template in a folder similar to this:

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEProjectTemplatesCSharpTest1033

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEProjectTemplatesCSharpTest1033

如果您在 32 位 Windows 上运行或具有不同的文化,您的路径可能略有不同,但您应该能够找到它.

Your path may differ slightly if you run on 32-bit Windows or have a different culture, but you should be able to find it.

单元测试文件模板

在 vanilla Visual Studio 中,单元测试的模板可以在与此类似的文件夹中找到(来自我的机器):

In vanilla Visual Studio, the templates for the unit test can be found in a folder similar to this (from my machine):

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEItemTemplatesCSharp1033

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEItemTemplatesCSharp1033

在此文件夹中有一个名为 SimpleUnitTest.zip 的文件,其中包含两个文件:

In this folder there is a file called SimpleUnitTest.zip that contains two files:

  • SimpleUnitTest.cs
  • SimpleUnitTest.vstemplate

您可以编辑 SimpleUnitTest.cs 文件以删除您不想要的所有代码,但您必须记住重新压缩该文件以使其包含您的更改.

You can edit the SimpleUnitTest.cs file to remove all the code you don't want to have, but you must remember to re-zip the file so that it contains your changes.

然而,如果你这样做,VS 可能不会很快接受你的更改,因为它在

However, if you only do that, VS may not pick up your changes anytime soon, since it maintains an unzipped cache of templates in

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEItemTemplatesCacheCSharp1033

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDEItemTemplatesCacheCSharp1033

因此,您还需要在那里编辑文件(或简单地将更改后的文件复制到那里).

So you will need to edit the file there as well (or simply copy your changed file there).

据我所知,VS 通常使用 ItemTemplateCache 中的模板,但偶尔会从 ItemTemplates 中恢复它们.应用更新时似乎会发生这种情况,但我还没有确定一致的模式,所以简单地在两个地方更新是修改我已经能够想出的模板的最佳方法.

As far as I have been able to tell, VS normally uses the templates in ItemTemplateCache, but occasionally reinstates them from ItemTemplates. This seems to happen when updates are applied, but I have yet to identify a consistent pattern, so simply updating in both places is the best way to modify the templates that I have been able to come up with.

这篇关于更改默认 MsTest 单元测试向导模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆