ReSharper, day 5: Integrated unit-test runner
Welcome to day 5 of my 31 Days of ReSharper, where I introduce you to ReSharper’s unit-test runner.
(The ReSharper test runner is also available for free as a separate download, if you don’t want to buy the full-fledged ReSharper.)
Now, why would the world need another unit-test runner? There are already so many ways to run tests. There’s the NUnit GUI, and the NUnit console runner. You can (and I have) write a rakefile that builds your solution using MSBuild and then runs the NUnit console, set up a Tools menu option to invoke it, and bind a keystroke to it. You can install TestDriven.NET. (You could even pay a lot of money for Microsoft’s test runner, although it doesn’t actually let you run the tests.) Don’t these cover just about every possible option?
Well, yeah. But ReSharper’s test runner is shiny. And being an IDE add-in, it manages some nice integration. Let’s take a tour.
Running all the tests
I’ve ranted about this before, so let’s start with the number one most basic feature of a testing tool: running all the tests.
Yes, ReSharper can do it, and it’s easy. The best way to run all the tests is to bind a keystroke (we use Ctrl+Shift+T) to the ReSharperAddIn25.UnitTestRunner_RunAllSolution command. Then, any time you hit Ctrl+Shift+T, it will automatically build your solution and run all the tests, showing the green (or red) bar as it goes.
If you don’t want it to be that easy, you can also go to the ReSharper menu > Unit Testing > Run All Tests from Solution. There are a couple of other options in the Unit Testing menu, but I ignore them, as they look like they do something other than run all the tests — and so far, we’ve done pretty well at keeping our NUnit tests fast.
Supported test runners
Out of the box, ReSharper’s test runner supports NUnit and csUnit tests. There’s also a third-party add-in to add mbUnit support to ReSharper UnitRun.
Integration
The ReSharper test-runner add-in really takes full advantage of being right there in Visual Studio.
-
Dockable. The test-runner window is dockable just like all the other IDE windows, so you can tuck it out of the way. I dock it to the bottom of the IDE, in a tab-set with the Output window and the various Search Result windows. (If you put it in a tab set, and a different tab is visible when you run the tests, the test-runner window will come to the front, just like you’d want it to.)
-
Key-bindable. As I noted above, it’s terribly easy to bind a single keystroke to mean “build everything, then run all the tests, and show me the results with a red or green bar”. So easy.
-
Pays attention. When you make code changes and rebuild, all the icons in the tree turn into little question marks, so you can see that you haven’t run the tests yet. But they keep their colors, so you can still see which ones passed and failed last time around. Here are screenshots of the “freshly run” (check marks) and “after rebuild” (question marks):


It’s even smart enough that, if you build your solution, but you haven’t actually modified any code, it won’t switch to the question marks. (I love this, because I’m always getting distracted by a conversation or something, and then can’t remember whether I just ran the tests or not.)
-
Jump to the code. Two nice features here. First, if you double-click on a test in the test tree, the editor shows the code for that test. Secondly, if tests fail, the test results pane puts hyperlinks into the call stack, and clicking one of those hyperlinks will jump to that location in the editor.

-
Gutter icons to run or debug a test. Wherever ReSharper notices a test method, it will show a little green-and-yellow circle in the gutter next to the code. If you click on that circle, you’ll get a dropdown menu with, among other things, an option to run that one test under the debugger. So if you want to put a breakpoint in a test and debug just that test, it’s easy.

Nothing in the ReSharper unit test runner is really groundbreaking, although the “jump to the code” features are pretty nice. It’s just that the features are all there, and they’re done well. If you do unit testing, give their test runner a try.

February 23rd, 2007 at 6:03 am
Wow! Thats something new! I use ReSharper since its beta of version 1, and Im glad you showed this new family member!
March 2nd, 2007 at 8:54 am
I used to have an add-in for VB6 that ran unit tests from the IDE which was fantastic, I really missed it and my use of unit tests faltered somewhat badly when I moved to C# and had to open NUnit and find the dll and run the test and well you know [I’m lazy!].
I love this feature in ReSharper, esp. the shortcuts in the gutter. I didn’t realise you could get a free version of the test runner – if for some crazy reason your not going to buy ReSharper then at least get the unit test runner, life becomes much more pleasant and you will get an idea how much better your IDE would be with ReSharper!
March 20th, 2007 at 6:18 am
I’ve been using Resharper 2.5 with VSTS2k5 for awhile now. We’ve been doing test driven development and therefore have numerous test methods. I love unit runner as we use nUnit.
However, I’ve been trying to get the Debug function to work but have been unable to do so. Any suggestions?
March 20th, 2007 at 6:21 pm
Debugging seems to work fine for me. It didn’t quite do what I expected when exceptions were thrown — I think it assumes they’re actually handled exceptions, even if they’re not handled inside the test method. But I can set breakpoints and it’ll stop when I start the test method with the debugger.
April 9th, 2007 at 11:44 am
I am using csUnit and I installed the UnitRunner only and it wont run my tests. It sees everything but always says Tests have not run. Any idea why? They run fine with csUnit.
June 28th, 2007 at 8:14 am
Expanding on the gutter theme, you can actually bind keystrokes to run/debug just the unit test/fixture in context. Don’t even have to take your hands off the keyboard to run the unit test.