locked
How do I change the default test code? RRS feed

  • Question

  • Hello,

    When VS 2010 creates a test class for me, it includes a whole pile of comments that were very useful the first or second time I did it, but are now becoming annoying.

    Can I change the default code that it creates?

    Thanks


    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
    Tuesday, December 21, 2010 6:03 PM

Answers

  • When you use the create unit test dialog there is a Settings button at the bottom left that allows you to control what is generated and how it is named.  You can turn off "enable documentation comments" and "Mark all tests as inconclusive by default" to remove a lot of the noise.

    If you want to change the template itself for the code that's generated you can edit the SimpleUnitTest.cs file C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\1033\SimpleUnitTest.zip, though I wouldn't recommend doing so. 

    • Marked as answer by Mr Yossu Sunday, March 6, 2011 2:44 PM
    Friday, March 4, 2011 7:06 AM

All replies

  • Hi,

    When you click on Test->New Test, select Basic unit test instead of unit test.

    Thanks,

    Anuj

    Tuesday, December 21, 2010 10:37 PM
  • Hi, Mr Yossu

    Of course, you can change it. When you have create a test project (for example TestProject1), it will create the default code or files, sometime you can delete the test (.webtest and so on) and then click the TestProject1, click right-click, you can create new test. Of course, you can change the default files name and so on!

                                                                                     Hope it can help you!


    When you help others, it's help yourself!
    Friday, January 28, 2011 7:17 AM
  • Thank you, but what I meant was, can I change what is pasted in? Is there a template somewhere, so that when I add a new test, it doesn't have all the extra stuff.

     

    Anuj pointed out that I can add a basic test, which is what I want. I would still be interested to know if I can modify the default, so that when I create a new test project, the initial test class doesn't ahve all the extras.

    Thanks anyway


    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/
    Sunday, January 30, 2011 3:46 PM
  • When you use the create unit test dialog there is a Settings button at the bottom left that allows you to control what is generated and how it is named.  You can turn off "enable documentation comments" and "Mark all tests as inconclusive by default" to remove a lot of the noise.

    If you want to change the template itself for the code that's generated you can edit the SimpleUnitTest.cs file C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\1033\SimpleUnitTest.zip, though I wouldn't recommend doing so. 

    • Marked as answer by Mr Yossu Sunday, March 6, 2011 2:44 PM
    Friday, March 4, 2011 7:06 AM