One of the many things I felt disappointed with Visual Studio 2012 was the removal of the "Create Unit Tests..." context menu. With the feature missing, creating unit tests have become more painful than before. The explanation from Microsoft was...
Generate Unit Test Wizard – In VS2010 you could right click on a method in your code and we would generate a unit test into your test project. This wizard was very tightly coupled to MS-Test and depended on features like Private Accessors to do its work, so it was cut. We are exploring alternatives here, but don’t have any good solutions yet.
Taken from here. But hey, what happens to those of us who are ok with MS-Test and don't really care about 3rd-party unit test frameworks? We want back the feature for our productivity!
Searching around the web, we will see that many developers have complained about it and most of them had given up. Doing some search and research there are actually a few ways to re-enable the feature. I will save the best one for last.
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. Thanks to the perseverance of my developer, Dawa Law, who seem to just refuse to accept that the option is gone *LOL*. He has even a better way but I'm just going to talk about the way I discovered after his continuous persistence in asking me about the issue.
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.
You will realized that the menu item is actually available in the context menu. :) The VS developers were kind enough to leave it there for us. *HeHe* Click on the Create Unit Tests... menu item and click either Move Up or Move Down. [Note: My screenshot is showing Create Unit Test in singular because I had previously tried to rename it]. Then click Close.
Restart Visual Studio 2012 and whalla! The context menu will be available!
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.
What about the 'Dawa Law' Method ?
I just thought to give a word or two on what my developer did to even simplify the re-enabling of the option. He actually exported his settings to a vssettings file and modified it to add the menu item. Other developers will only need to import the settings file and the option will be enabled - How thoughtful was that? :) Of course, the caveats still apply. I will leave it to him to explain it as the credit goes to him.
If you are like me who wants to see the option being added back Out-of-the-box in Visual Studio 2012, don't forget to vote for it here.
Have fun unit testing! :)
Home » Visual Studio » Right-Click, Create Unit Tests...
Right-Click, Create Unit Tests...
20:04
Jurnalis Jalanan
Labels:
.NET,
Developer Community,
Visual Studio
Popular Post
-
I have just gotten a MacBook Pro for work and like all the other notebooks before it, the first thing I would do is to install Windows Serve...
-
D oing mobile development? Then, checkout the Mobile Client Software Factory CTP from the Patterns & Practices group.
-
V8 / 3.523 cc / 335 PS / 381 lb/ft (517 Nm) @ 3.650 / supercharger (click images for a larger view)
-
This wooden Harley made from 4x4 pieces of wood is for the rider who is tough as nails.
-
Carloft Berlin, 10 loft suites + 1 panorama loft penthouse (click images for a larger view)
-
I passed! I passed! Just received news that I passed my Exam 70–441 : PRO: Designing Database Solutions by Using Microsoft SQL Server 2005 ...
-
F or those who are interested in VSTS and MSF, do check-out the following event. David Anderson is flying all the way here to give the talk ...
-
Photo: Diane Edwardson, June 15, 2012. This may be the last photo of Red Tailed Hawk Baby #4 in the nest. (Click on photos to enlarge.)...
-
On Wednesday, August 29, TMC Fuel Injection System LLC filed a lawsuit in the U.S. District Court in Philadelphia against Ford Motor Compan...
-
V8 / 8.193 cc / 600 PS / 600 lb/ft (813 Nm) @ 2.000 / biturbo / 0 - 100 mph (160 km/h): 8,0 s / Vmax: 200+ mph (320+ km/h) (click images for...



No comments:
Post a Comment