TestDriven.NET keyboard shortcut

Continuing with the Palermo brain dump theme, Jeffrey introduced me to a keyboard shortcut for running TestDriven.NET tests from a keyboard shortcut.  I had been right-clicking and going from the context menu:

While the context menu is nice, it has me reaching for the mouse (like a chump).   Instead, I can set a keyboard shortcut to perform the same context-sensitive testing.

To set the keyboard shortcut, first go to “Tools->Options…” to bring up the Visual Studio Options dialog, then select the “Environment->Keyboard” screen:

In the “Show commands containing:” text box, enter “TestDriven” to get the the TestDriven.NET command quickly.  Select the “TestDriven.NET.RunTests” command and click the “Press shortcut keys:” text box.  Now enter the keyboard shortcut you like (I use ‘Ctrl-T’) and click the Assign button.  The shortcut key is not assigned until you click the “Assign” button.

Once you assign the shortcut, I additionally set the “Use new shortcut in:” to “Text Editor”.  For some reason, setting “Global” wasn’t enough, I had to set the “Text Editor” command also.

With this keyboard shortcut in place, you don’t need to lift your hand to the mouse after writing your test.  The shortcut also works everywhere the TestDriven.NET menu works, so I can select a file, project, or solution in the Solution Explorer and run all of the tests with a quick keystroke.  Since the context menu gets pretty unruly, I save some time I normally spend searching through a menu that now stretches my entire screen.

About Jimmy Bogard

I'm a technical architect with Headspring in Austin, TX. I focus on DDD, distributed systems, and any other acronym-centric design/architecture/methodology. I created AutoMapper and am a co-author of the ASP.NET MVC in Action books.
This entry was posted in Tools. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • As an added benefit, if you are using ReSharper as well as TestDriven.NET installed you can do the same behavior in R# 3.1 or above. Follow the same instructions as here, in the commands containing type ContextRun. You can bind this to Ctrl-Shift-T. This will run only the test where to cursor is, or if the cursor is placed at the class level, it will run all tests for that class. It is currently not possible to bind a shortcut to run ALL tests in ReSharper however.

  • Wow… How did you get by without this before!!

    TD.NET and R# work the same way with contexts:

    - In or on a method, run that test
    - In between or before/after methods in a class, run tests in that class
    - In a class (.CS) file, but outside the class (namespace, etc) it still only runs that test class
    - In Solution Explorer, selecting a file and CTRL+T on a file runs tests in that file, folder? that folder, project? that project solution? entire solution.

    There’s a shortcut to get the solution exp into focus, but I forget what it is.

  • > There’s a shortcut to get the solution exp into focus, but I forget what it is.

    Ctrl-Alt-L. I use my Ctrl-Alt-L + Alt+H (hides tool window) combo all the time. :)

  • Jimmy, thanks for getting the good word out there. I could not breath without my TestDriven.Net shortcuts.

    Alt+R — Run test
    Shift+Alt+R — Rerun the last test (this one is Really handy)
    Alt+D — Debug test
    Shift+Alt+D — Debug the last test

    The ability to re-run your test makes the Red-Green cycle go by much quicker. Write your test/code. Alt+R (Red). Write code to make your test pass. Shift+Alt+R (Green). No need to go find your test code to re-run the test.

  • I am a big fan of driving R# using the standard shortcut /menu keys.

    run all tests Alt + R + U + N (RUN)
    run current test Alt + R + U +

    I have a very simple mind so the RUN command works well for me.

  • Great post, extremely helpful, thanks!

  • Ryan Vice

    I always seem to find myself on your blog Jimmy… You da man!

  • Mert

    That is  what  I was looking for. You need to set the “Use new shortcut in:” to “Text Editor”. Otherwise current TextEditor shortcut will override your global choice, and it won’t work.