locked
Can I change the default test code that VS2010 creates for new tests? RRS feed

  • Question

  • Hello,

    I'm fairly new to unit tests, and am trying to get up to speed on them. I'm building a set of tests for a project, and am using the context menu's item of "Create Unit Tests..." to create the basic test code.

    The first couple of times I did this, the extra comments in the test code were very helpful, but now I've done it a few times, they're just clogging up the code. I usually delete them all before I start writing the test code.

    Any way to change the default code that's put in the tests?

    I'm using VS2010 Professional if it makes any difference.

    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/
    Wednesday, December 15, 2010 5:55 PM

Answers

  • I'll provide the same response as on your other thread here:

    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.


    blog: http://www.richard-banks.org podcast: http://www.talkingshopdownunder.com
    • Marked as answer by Mr Yossu Sunday, March 6, 2011 2:48 PM
    Friday, March 4, 2011 11:14 PM

All replies

  • Hi,

    When you click on Test->New Test, select Basic unit test instead of unit test. This wouldnt generate the default code.

    Thanks,

    Anuj

    Tuesday, December 21, 2010 11:13 PM
  • Hi,

    Thanks for that. I had never used that method of creating tests, so didn't spot the option. I had just right-clicked in the code itself, and chosen "Create unit tests..." which used the version with the comments. That has the benefit of creating the basic test code for you.

    Do you know if there's a way of getting the wizard (which is what is used when you use my way of creating tests) to use the basic test code instead of the fully commented code?

    Thanks again


    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/
    Wednesday, December 22, 2010 2:16 PM
  • I'll provide the same response as on your other thread here:

    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.


    blog: http://www.richard-banks.org podcast: http://www.talkingshopdownunder.com
    • Marked as answer by Mr Yossu Sunday, March 6, 2011 2:48 PM
    Friday, March 4, 2011 11:14 PM