Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

visual studio 2008 - Change Default MsTest Unit Test Wizard Template

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, you can, on several levels:

Project Template

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

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.

Unit Test File Template

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

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

  • SimpleUnitTest.cs
  • SimpleUnitTest.vstemplate

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.

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...