ReSharper Shortcut for Context-Sensitive Unit-Test Running

For a keyboard shortcut to the context-sensitive ReSharper unit test runner (otherwise available via right-click > Run Unit Tests), map:


Edit: In ReSharper 6, this has moved. It is now
(Note the extra ReSharper in there; that’s not a typo.)

(Thanks to Clinton for mentioning it.)

What This Solves

The slowest way to select and run unit tests is to click the green-yellow bubbles in the left margin and pick “Run” (or “Append to Session” to collect a bunch of them to run).

From the right-click menu, the “Run Unit Tests” option will run a test if your cursor is in a test, all tests in a fixture if your cursor is outside a test but within the fixture, or all tests in a file if you’re outside any fixtures.

Mapping the ReSharper.ReSharper_UnitTest_ContextRun to a keyboard shortcut achieves the context-sensitive behavior, mouse free. I chose Alt-T for mine, since that wasn’t in use for anything else. (Have a nice strategy for picking unique keyboard shortcuts and remembering them? Please share in the comments.)

To Map the Shortcut

Tools > Options > Environment > Keyboard. In the “Show commands containing” textbox, enter some or all of the command, and select the command.

Set your focus to the “Press shortcut keys” textbox and type your shortcut just as if you were invoking it. If a command shows up in the “Shortcut currently used by” list, life will be simpler if you pick a different shortcut. When you have one you like, click “Assign” and “OK.” Good to go!

About Sharon Cichelli

I am a Principal Technical Lead at Headspring, developing enterprise-changing software and coaching teams to deliver value without death marches. I am a .NET developer, open-source contributor, user group organizer, technical blogger, pinball fan, and Arduino enthusiast.
This entry was posted in Resharper, shortcut, unit testing, Visual Studio. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • I think that running unit test in the debug mode is also handy so I chose combo CTRL+T,CTRL+R for Test Run and CTRL+T,CTRL+D for Test Debug.

  • Thomas Eyde

    I run my tests way more than I debug, so I can live without the debug shortcut.

    I map context run (ALT + ‘), current session (CTR + ALT + ‘) and solution (SHIFT + CTR + ALT + ‘).

    Then I can pick a convenient subset with ‘context run’, and run them all with ‘current session’ while I fix or implement something.

    On a keyboard with Norwegian layout, the apostrophe and asterisk are located on the same key right next to the enter key. It’s convenient to use the left hand for the control keys, and the right hand for asterisk/apostrophe.

    One major pain with these mappings, is that they disappear when a new version is installed.

  • Mike

    The best move I ever made was mapping F1 to VisualSVN checkout Ctrl-F1 check in. Now when I accidentally hit F1 I don’t have to wait 5 minutes for the help menu to load.

  • Thank you Sharon. I just mapped mine.

  • Unfortunately this command doesn’t seem to exist in R# 6 anymore…