Where is the "Create Unit Tests" selection?
Solution 1
This feature was cut from VS.
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.
EDIT There is a work around: http://blogs.msdn.com/b/malaysia/archive/2013/02/20/right-click-create-unit-tests.aspx
Solution 2
The "Unit Test Generator" extension is available
To add directly from Visual Studio 2012/2013 IDE:
- Menu: Tools -> Extensions and Updates
- Click: Online -> Visual Studio Gallery
- Search for: "Unit Test Generator"
Note: MSTest in VS 2012/2013 still sucks
Solution 3
The menu item is still in place, but for unknown reasons it's invisible in the code editor. But you can use visual studio commands to run unit test wizard. The command you need is
EditorContextMenus.CodeWindow.CreateUnitTests
Open Command Window and type the command there. Or type an alias command as follows
alias ut EditorContextMenus.CodeWindow.CreateUnitTests
and assign the alias to run command faster.
Another way to run the wizard is keyboard shortcut. In Visual Studio open
Tools -> Options -> Environment -> Keyboard
Type "createunit" in "Show commands containing" text box to filter out CreateUnitTests command, select it. Choose "Text Editor" in "Use new shortcut in" combo, and press shortcut you want in "Press shortcut keys" text field (e.g., Ctrl+T, Ctrl+C). Finally, press Assign button. Enjoy!
Solution 4
Here is how to to enable it again :
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.
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.
Click on the Create Unit Tests... menu item and click Move Down until it's on/under the "Run tests.." Command. Then click Close.
Restart Visual Studio 2012 and that's it ! The context menu will be available!
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.
Source(with images, i don't have enough Rep Points to put them) :
http://serena-yeoh.blogspot.fr/2013/02/visual-studio-2012-create-unit-test.html
(ps : read the Caveats !!!! )
Solution 5
The answer of intrueder didn't work for many users. When I enter UT in a command window, I sometimes had the following
>UT
Command "EditorContextMenus.CodeWindow.CreateUnitTests" is not available.
But sometimes it worked for the same solution, so behavior seemed to be intermittent.
With a help of Dawa Law's post “Create Unit Tests… Function Not Available Or Disabled" I found that during each Visual Studio session you need to create one test class manually before wizard will be available.
If you have an existing Unit Test project in the solution,
At Solution Explorer, right click the Unit Test project –> Add –> Unit Test… This will create a new unit test class and trigger Visual Studio that an existing Unit Test class is available, thus enables Create Unit Tests wizard. Note: You may delete the created Unit Test class file (UnitTestX.cs) as it is used to trigger the function.
If you do not have an existing Unit Test project in the solution, you need to create it before adding a manual class:
Go to File –> Add –> New Project… In the Add New Project window, select Installed –> Visual C# –> Test –> Unit Test Project. Give it a meaningful name and click OK
The Dawa Law's post “Create Unit Tests…” Function Not Available Or Disabled has snapshots to illustrate each step.
Note, that VS 2012 Create Unit Tests Wizard support generation tests for public methods only, when in previous version private methods were also supported.
.
Related videos on Youtube
Houman
I'm a thinker and a dreamer. Love pets but don't have any. I'm a passionate tech entrepreneur.
Updated on July 08, 2022Comments
-
Houman almost 2 years
I have installed the new Visual Studio 2012 Ultimate.
I have created a Test Project with my solution and it contains some default unit tests. However right clicking on new Methods doesn't show the "Create Unit Tests" context menu any longer.
See Visual Studio 2010 Ultimate:
And Visual Studio 2012 Ultimate:
Any idea why that could be?
UPDATE:
Solution for Visual Studio 2012 and 2013:
Microsoft has acknowledged it here and offers an official work around patch to fix it. Download, install and Enjoy!
-
Daniel A. White about 12 yearsare these both the same project or mvc build?
-
Houman about 12 yearsThese are new MVC 4 projects built from scratch.
-
Diego about 12 yearsInteresting. What happens when you click in "Run Unit Tests" ?
-
Daniel A. White about 12 yearsi would report this as a bug.
-
JaredPar about 12 yearsVS 11 did move a lot in the direction from providing a test infrastructure via MSTest to providing a pluggable test framework. This could be a fallout from that decision. Either way I would file a bug
-
furier almost 12 yearsme to want this feature! WTH now i have to write so much code manually T_T
-
Sebastien H. about 11 yearssolution here : serena-yeoh.blogspot.fr/2013/02/… read the Caveats !!!!
-
Ahmed Elbatt over 9 yearsStill not working even after running GenerateUnitTest.vsix according to your update.Do you have an idea ?
-
Serge Voloshenko about 7 yearsCan someone add an answer for VS 2017 community edition, plz? I'm looking into MS documentation but I don't have the options in context menu: docs.microsoft.com/en-us/visualstudio/test/…
-
-
Andrew Harry almost 12 yearsHope they come up with a working solution. Seems like a large step backwards otherwise
-
habakuk over 11 years
-
LockTar over 11 yearsI can't get this to work. I set my cursor on the method. Hit the shortcode I added but then get a message: Command "EditorContextMenus.CodeWindow.CreateUnitTests" is not available.
-
intrueder over 11 yearsI've tried on Visual Studio 2012 Ultimate with update installed, may be it matters.
-
saadan over 11 yearsI get the same error as LockTar when i try this. So the easyest way to use unit test is to make a new unit test projekt.
-
intrueder over 11 yearsI can't explain why you got an error, but I've grabbed the proof video and you can watch it at grabilla.com/02c0a-6f42a829-1535-4016-a7ff-cbbda665bee5.html
-
Michael Freidgeim about 11 yearsIf wizard is not available, See the blog dl.my/2013/create-unit-tests-function-not-available-or-disabled or my answer below stackoverflow.com/a/15184716/52277
-
Michael Freidgeim about 11 yearsNote, that VS 2012 Create Unit Tests Wizard support generation tests for public methods only, when in previous version private methods were also supported.
-
Michael Freidgeim about 11 yearsNote, that VS 2012 Create Unit Tests Wizard support generation tests for public methods only, when in previous version private methods were also supported.
-
Nathan Smiechowski over 10 yearsThat has helped me a lot, thank you very much. I was missing the add a dummy unit test step in my remedy.
-
Jorj almost 10 years"you need to create one test class manually before wizard will be available" - that did the trick to me in the end
-
Sander almost 10 yearsLooks like the third option in that workaround isn't available anymore in VS2013.
-
Ahmed Elbatt over 9 yearsThanks I used Dawa Law's blog and it is done finally :)
-
indolentdeveloper over 9 yearsManually creating one unit test of important. Silly not sure why the menu item was disable till then.
-
LosManos about 9 yearsIn my version of Visual Studio that has QuickLaunch (the textbox in the upper right corner) one can just write "CreateUnitTests" (or even shorter) to get to the command.
-
LosManos about 9 yearsThe functionality is coming back in VS2015 blogs.msdn.com/b/visualstudioalm/archive/2015/03/06/… thanks to the ones that voted for it in visualstudio.uservoice.com/forums/121579-visual-studio/… . @furier : Maybe you voted for it?
-
BrainSlugs83 about 7 yearsI mean, it was there 5 minutes ago... it's just not there now -- why does it come and go?
-
Luke Puplett about 6 years...and then what? It's already listed in there but it ain't showing when I right-click.
-
Sunny Tambi about 6 yearsFound the same thing here as well .. dawalaw.com/2013/enable-create-unit-tests-on-visual-studio-2012