views:

243

answers:

1

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

+5  A: 

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.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033

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.0\Common7\IDE\ItemTemplates\CSharp\1033

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.0\Common7\IDE\ItemTemplatesCache\CSharp\1033

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.

Mark Seemann
Unfortunately it only works for "Unit Test" item template, but "Unit Test Wizard" use template from somewhere else.
Regent
Regent, do you happen to know where that is? I need to modify that Wizard to use the same cs file. We added some code to the MyClassInitialize and we need it to exist everytime a new test is created. Thanks.
AboutDev