Using ReSharper as an essential part of your TDD toolkit

I have been a long time and fan and user of JetBrain's ReSharper add-in for Visual Studio .NET. At a high-level, ReSharper is a productivity and refactoring plug-in for Visual Studio, but that simple description belies the genius behind the product.

As a TDD advocate and practitioner, I have found ReSharper to be absolutely indispensable in writing tests, writing the implementation, getting the tests to pass, and then refactoring. The "Red -> Green -> Refactor" rhythm is essential to writing testable, robust, and correct code the first time. My experience with ReSharper 2.0 and NUnit has led me to a surprising productivity boost by shortening the feedback loop between constructing a test, implementing the minimal amount of no-fluff code to make it pass, and then refactoring the code as/if necessary.

Out of the box, ReSharper 2.0 offers unit testing support for NUnit test fixtures (future plans include MBUnit and possibly Team System fixtures). ReSharper brings enhanced IDE integration through a tool window that lists all of your tests in the familiar NUnit tree view:

But wait! There's more!

Inside your unit test fixtures, ReSharper adds some icons to the left of your code window to run either a particular test or all tests within the current fixture.

For example, it's easy to run all the unit tests in a particular fixture:

Or you can easily run tests at the individual method level:

From this context menu, at an individual test method level, you can run a unit test directly without navigating to the Unit Test Runner tool window. In addition, you can choose to run JetBrain's DotTrace code profiler against the particular test. (I won't bother to comment on the easy to access "Debug" option, as it may lead to Test Driven Debugging…).

From my experience, ReSharper has been a great boost to my personal productivity. The only downsides for me have been the slow loading times (due to parsing of all the projects and referenced assemblies in your solution) and some minor stability issues for some of the post-2.0 preview builds (build 257 seems relatively stable so far).

One of the most important things to consider when adopting a new tool or technique is how "friction-less" it fits into the way you develop your code. ReSharper has been great in this particular aspect, in addition to having some great(!) code generation features, such as the ability to generate new classes and methods as you write your unit tests:

Also helpful, too, is the ability to quickly navigate between code files spread out across many projects in larger solutions with CTRL-SHIFT-N:

And also the ability to quickly navigate to variable/method/class declarations with CTRL-Click (ReSharper highlights the current text under your mouse when you hold CTRL):

If you're a keyboard/shortcuts junkie, if TDD drives everything you do, and if you're looking for a way to take the drudgery out of writing code, you may be interested in giving ReSharper a spin.

You can download the "released" version from this URL http://www.jetbrains.com/resharper/

And you can download the latest EAP preview build (currently 257) from http://www.jetbrains.net/confluence/display/ReShar…

Finally, if you're interested learning more about Test Driven Development, Mock objects, and more, be sure to check out Jeremy's most excellent post Best of the Shade Tree Developer.

[tags: resharper,tdd,refactoring]

This entry was posted in ReSharper. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

6 Responses to Using ReSharper as an essential part of your TDD toolkit

  1. Carsten hess says:

    I just spotted that James Kovacs have written a ReShaper-plugin for running VSTS UnitTests: http://www.jameskovacs.com/blog/IntroducingVstsUnitPluginForReSharper.aspx

  2. paul.laudeman says:

    Kiwidude – Sure, I agree with your feelings… The initial release of 2.0 was a pig performance wise and subsequent builds have gotten better in this regard, but it is still noticeable (as I mentioned in my post). All I can say about your experiences with ReSharper is to keep an eye out for the 2.1 release which is right around the corner, and hopefully it might address some of your/our concerns. Your other points about the pro’s of TDD.NET are right on target, of course!

    Karl – Yes, it is worth giving these tdd featues a short, especially if you are using NUnit on a regular basis. I find that it is very convenient to stay in the IDE as much as possible to help keep the flow. :-)

  3. karl says:

    Paul:
    I use Resharper a lot…love it. Just never really used the unit test parts of it…I’ll give it a go…habits are hard to break though :)

  4. kiwidude says:

    Paul,

    I won’t argue at all that Resharper 2.0 has some great features especially compared to VS2005 by itself but I just can’t cope with the absolutely appalling slowdown of the Visual Studio IDE Resharper introduces. Startup time for the IDE increase by up to 15 seconds, every keystroke in the IDE becomes sluggish, it crashes for me once every four or five times of exiting and there are still so many irritating bugs its not funny. I’ve been a huge Resharper fan of the 1.5 versions but 2.0 imho is unusable for people who do a lot of chopping and changing between projects all day as I do…

    It’s been uninstalled and will remain so until (or if) those guys at JetBrains pull finger and sort out those issues – approx 4,500 of them listed on Jira…

    I’ll take the more lightweight, stable, richly featured (Test with Coverage, Test with Reflector, multiple testing framework support etc) TestDriven.Net add-in any day of the week over this bloat… we all have our preferences… ;-)

  5. Hi Karl,

    I like TestDriven.NET and have in fact used both of them side-by-side. However, I am rather addicted to the visual indicators of my test results and that is a definite plus to me. TDD.NET only outputs to the VS.NET output window and you have to scroll up through the output to find out information about failing tests, etc.

    One definite plus to TDD.NET at this time is that it supports VSTS test fixtures, which ReSharper unfortunately does not. This is a bit of a mixed benefit, though, at least for me as I find that time the time it takes to compile and run the VSTS fixtures takes quite a bit of time, at least in comparison to NUnit fixtures. (Of course, I still need to download and give the latest version of TDD.NET a run and compare my experiences with the latest bits.)

    Another plus to using TDD.NET is that you get integrated support for code coverage reports and visualization through NCover. This feature alone rocks because the integration is so slick! ReSharper doesn’t offer any comparable feature in this area at this time.

    In the end, even without the unit testing support, I’d choose to use ReSharper any day at least for it’s refactoring and code gen abilities. Once you get started with it, get the keyboard shortcuts memorized, etc., you can really get into the red-green-refactor flow, and whatever tool that can do that for me without getting in my way gets a big thumbs up. If you use truly use TDD to guide your development, and let ReSharper help you to that end, you’ll appreciate the productivity boost.

    -Paul

  6. karl says:

    Paul:
    How do you feel it compare to TestDriven.NET?

Leave a Reply