Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 334
Ryu Avatar asked Sep 23 '09 20:09

Ryu


People also ask

Is MSTest deprecated?

Test projects that are Coded UI tests or Web Load Tests are not compatible with MSTestV2. These project types have been deprecated.

Is MSTest a testing framework?

MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE. It is also referred to as the Unit Testing Framework. However, MSTest is the same within the developer community. MSTest is used to run tests.


1 Answers

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.

like image 140
Mark Seemann Avatar answered Sep 30 '22 07:09

Mark Seemann