Visual Studio shortcut for Create new Interface and Create new Basic Unit Test

8.6k views Asked by At

In Visual Studio you can press SHIFT+ALT+C to create new class file. I am looking for similar shortcut for new interface file and new "basic unit test" file. I have Telerik JustCode so please do not suggest simillar product. But if a small extension exists for example, it would be nice to know. BTW I am using Visual Studio 2010 (C#).

3

There are 3 answers

3
Joey On BEST ANSWER

There are no built-in solutions for this, but you can easily record macros (In the Tools menu):

enter image description here

You can rename them in the Macro Explorer (Alt+F8)

You can then assign shortcuts to those macros in ToolsOptionsKeyboard.

EDIT This doesn't work for adding a new Basic Unit Test. You'll only get to the New Test selection dialog, even with this method.

0
Carlo V. Dango On

Rather than using a macro, I would advice you to look into the Code Snippet Manager. It enables you to set up a template of text with "holes" in it. And assign the template to a "key" - a short text (which can be autocompleted). When the key is typed the template replaces the key and the holes can easily be filled out. Further, you can add macro-like functionality to it, to automatically get the current filename or class or date pre-filled.

Visual studio actually is shipped with C# snippets for "Test class" and "Test method".

See also http://msdn.microsoft.com/en-us/library/ms165393(v=vs.100).aspx

Finally, the code snippet support in Resharper (http://www.jetbrains.com/resharper/) is much better than the one in visual studio. Definitely worth checking out. A real productivity boost!

0
Maarten Bodewes On

In the new Visual Studio 2019 (Preview, in my case) it seems that Alt-Shift-C opens up "Add New Item" with the "Class" option selected and the cursor in the (file) name field. However, at that point you can simply switch from "Class" to "Interface" or any other available item.

If "Basic Unit Test" is missing then that might be because your project is not a test project; the items listed seem particular to the project type.