Where is the “Create Unit Tests” selection?

前端 未结 9 1336
情歌与酒
情歌与酒 2020-11-30 19:25

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 clickin

相关标签:
9条回答
  • 2020-11-30 19:44

    This feature was cut from VS.

    http://blogs.msdn.com/b/visualstudioalm/archive/2012/03/08/what-s-new-in-visual-studio-11-beta-unit-testing.aspx

    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

    0 讨论(0)
  • 2020-11-30 19:45

    The "Unit Test Generator" extension is available

    Unit Test Generator Extension

    To add directly from Visual Studio 2012/2013 IDE:

    1. Menu: Tools -> Extensions and Updates
    2. Click: Online -> Visual Studio Gallery
    3. Search for: "Unit Test Generator"

    MSDN Video Demonstration

    Note: MSTest in VS 2012/2013 still sucks

    0 讨论(0)
  • 2020-11-30 19:45

    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.

    .

    0 讨论(0)
  • 2020-11-30 19:45

    "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."

    (Michael Freidgeim)

    0 讨论(0)
  • 2020-11-30 19:47

    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!

    0 讨论(0)
  • 2020-11-30 19:49

    You may regain the right click "Create Unit Tests..." by importing the following vssettings from here.

    0 讨论(0)
提交回复
热议问题