Enable “Create Unit Tests…” Workaround on Visual Studio 2012

Update: A better solution posted! Check out this post!

As you might have known, Visual Studio Team has decided to depreciate this functionality in Visual Studio 2012. Excerpt from Visual Studio Team blog:

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.

What does this mean?

It means that those who survived with MS-Test will now have to create unit tests manually. On the other hand, they have yet to come out with a solution here. But it seem like this causes furore from developers community who voiced out their opinion to bring back “Create Unit Tests…” functionality.

There are several alternative methods to bring back this function back into Visual Studio 2012. Fortunately, Visual Studio Team has yet to fully eliminate “CreateUnitTests” from the latest Visual Studio (as of VS 2012 Update 1). After some ample research and sheer perseverance, a few workarounds and solution are created. I will start off with workarounds first, and with permanent solution in my next blog post.

Workaround 1: Keyboard Shortcut

This is workaround was discussed in Stack Overflow and it provides you keyboard shortcut to the function.

  1. In Visual Studio 2012, go to TOOLS –> Options.
  2. Then select Environment –> Keyboard. At “Show commands containing:” text box, input “CreateUnitTests” without quotes.

    Visual Studio 2012 Options Window focussing on Environment --> Keyboard
    Visual Studio 2012 Options Window focussing on Environment –> Keyboard
  3. Assign shortcut keys (In this case, I assigned Alt+C because it is unused in Visual Studio 2012 Premium) and click “Assign” button.
  4. Then click “OK” button.
  5. Now when you use the shortcut (Eg. Alt+C), Create Unit Test window will appear.

[adrotate banner=”1″]

Workaround 2: Command Window

In the same discussion in Stack Overflow, a workaround with Command Window was provided.

  1. Launch Command Window on Visual Studio 2012. You may get this by:
    Clicking: View –> Other Windows –> Command Window
    Keyboard shortcut: Alt+W, A.
  2. In Command Window, key in:
    alias ut EditorContextMenus.CodeWindow.CreateUnitTests

    Command Window with Create Unit Tests command
    Command Window with Create Unit Tests command

There you go, workaround for “Create Unit Tests…” functionality.

Happy Unit Testing!

5 thoughts on “Enable “Create Unit Tests…” Workaround on Visual Studio 2012”

  1. >alias ut EditorContextMenus.CodeWindow.CreateUnitTests ut
    Command “EditorContextMenus.CodeWindow.CreateUnitTests” is not available.

    This is what happened to me when I tried the Command Window workaround. I tried the keyboard shortcut workaround, there I am having no results. But when I tried the solution mentioned in http://dl.my/2013/enable-create-unit-tests-on-visual-studio-2012/ I am getting ‘Create Unit Tests’ grayed out.

    Is there anything I could be missing out or something else that I could try?


Leave a Reply