Megosztás a következőn keresztül:


Right-Click, Create Unit Tests

For those who are disappointed with the removal of the "Create Unit Tests..." context menu in Visual Studio 2012, here are few methods for you to re-enable the feature:

Method 1 - Command Window
If you find hard enough, you will discover that the command to invoke the Create Unit Tests... is actually:
EditorContextMenus.CodeWindow.CreateUnitTests
You can actually type that in the Command Window to invoke the Create Unit Test Wizard. If you find it too verbose, you can actually create an alias for it.
alias ut EditorContextMenus.CodeWindow.CreateUnitTests
Then just type ut to launch the wizard.

Method 2 - Keyboard Shortcut
The next method is to go to Tools->Options->Environment->Keyboard and set a shortcut key of your preference.

Method 3 - Re-enable the Create Unit Tests... Context Menu.
This is by far the best method ever. To re-enable the Create Unit Tests... menu, go to Tools->Customize... to launch the Customize dialog. At the Customize dialog, go to the Commands tab, select the Context menu radio button and choose Editor Context Menus | Code Window.

Thanks to our MVP Serena Yeoh for sharing such a great information with us, you can click here to see the full details.

Comments

  • Anonymous
    February 22, 2013
    Definitely voting to bring back this feature to VS2012. Voting is being considered already: visualstudio.uservoice.com/.../2748862-add-create-unit-tests-menu-option-back-

  • Anonymous
    March 02, 2013
    Your re-post missed the most important part of the original blog: CAVEATS You may discover that using any of the above methods may not work. i.e. The Command Window will tell you that the command is not available, the keyboard shortcut will not fire or the Context menu will be available but disabled. To allow all these to work, you will first need to have a Unit Test Project in your solution. After creating the Unit Test Project, you will need to manually Add a Unit Test item to the project even though the project unfolds with one on its own. After you have done this, everything will function as it is like back in Visual Studio 2010. You can safely remove those UnitTest1.cs files.

  • Anonymous
    June 14, 2013
    Thanks full post and michael freidgei's work around to enable create unit test helped me a lot.

  • Anonymous
    July 14, 2013
    There seems to be a step missing in "Method 3" I see the "Create Unit Test" option in the customize window as shown in the screenshot... but do I need to do something to it to enable it?

  • Anonymous
    July 30, 2013
    Hi Wes, were you able to enable "Create Unit Test"? I still can not figure out how to enable it.

  • Anonymous
    July 30, 2013
    If you use the link at the bottom of the post it has more information. You have to move the unit test up and then down, close, and restart the program. serena-yeoh.blogspot.com/.../visual-studio-2012-create-unit-test.html

  • Anonymous
    October 28, 2013
    I got it to work. But... How can I test non static methods? The wizard only sees static methods.

  • Anonymous
    February 26, 2014
    This is great in VS2012 - but it does not work in VS2013 - Microsoft seem determined to remove this feature.

  • Anonymous
    March 26, 2014
    I have tried the options suggested and none of them work for a console application in visual studio 2013 ultimate if you create an MVC project it will auto generate the utest unit class for you but not in a console app it comes back with Command "EditorContextMenus.CodeWindow.CreateUnitTests" is not valid. when you try the command window

  • Anonymous
    May 15, 2014
    VS 2013 ultimate (v 12.0.30110.00 update 1) CreateUnitTest does not exists in any of the three choices. I did create a test project and manual test script, that works. But these Generate does NOT exists in my version of VS.

  • Anonymous
    June 15, 2014
    Non of the method works for 2013 ..

  • Anonymous
    September 30, 2014
    Michael freidgeim, Thanks a lot. It worked for me using VS 2012