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
-
Writing is hard. Writing for an agent is even harder. Writing for an editor considering your book but wanting a rewrite first is like climbi...
-
Intro Ahh... My new blog spot. Loke Uei from Microsoft Malaysia has recommended me to blog here as he can't stop laughing at me for blo...
-
Golden Dream Rolls Royce with Hemmy - by Ivan Mitev Photography I stumbled upon this ostentatious golden beauty tonight and had to put it up...
-
My best mooncake award for this year goes to Baker's Cottage 's snow-skin yam mooncake! Absolutely yummy! But mom prefers her Cosway...
-
Complacency - a word usually used to describe folks who take it too easy at work and to some extent, not motivated to do better beyond '...
-
Photo: Diane Edwardson, November 1, 2011. Cat skull. (Click on photo to enlarge.)
-
I t has been one month now since I've joined Microsoft and you must be wondering how am I doing? I'm doing great at the moment and ...
-
I'm a little demotivated lately with the type of work that I'm assigned to. I feel that my skills and talents are not fully utilized...
-
One of the proposals that Ferrari didn't liked... I have LOTS of them in fact.
-
Regular readers will remember that last month we reported with fury and disbelief the upswing in recorded users of pedal cycles in Aberdeen...



No comments:
Post a Comment