Announcing the Test Driven Development Productivity Plugin for Resharper

Why does visual studio make doing the right thing, so hard to do?

easy_button

The background

This last weekend during the Pablo’s Day of Test Driven Development workshop held in Austin, Tx I decided to solve a problem in visual studio that has bothered me for the last two years.  In the process of following TDD using resharper I would normally create a test class.  Than write a line that instantiates a class that has not been created yet.  This would leave me with code that looks like this.

TestFirst

All of the classes and interfaces in red do not exist.  Resharper is nice enough to highlight the non-existent definitions in red.  The next step is to get this code to compile, which requires the classes to be created.  Using the resharper quick fix menu, it is easy enough to generate the code for each of these types.  This is where the problem starts.  The resharper stubbed code is dropped into the end of the current file.  Since I separate my UnitTest code from my production code using separate Visual Studio projects, I am now forced to move the type definitions into a separate project.  The problem I have with moving the inline code into a new file in a different project is that this process takes a handful of steps, which although are very trivial, to complete.  The process of cutting and pasting code into a new file gets in the way of what I want to do which is: 

Design functionality by writing test code, Implement functionality by making my tests pass, & Make the implementation code easier to read by refactoring. 

The last thing that I want to worry about is organizing my files and namespaces.  I want visual studio to just do the right thing.  To use the Microsoft mantra make me fall into the pit of success, rather than the dark hole of cluttered files and project folders.  I understand that I am asking for a lot from visual studio…. I mean its name starts with Visual which means lots of mouse clicks and Drag & Drop development. The important point to remeber is that when practicing TDD it is much more important to be able to concentrate on good design rather than having some code auto generated with a few mouse movements. 

My Solution

I decided to take advantage of the tools I have at my disposal to solve this problem.  I first looked into somehow making a smart tag that would show up in visual studio.  Although there is a SmartTag interface and a class in the visual studio sdk.  The documentation on creating a smart tag is non-existent.  I suppose I could email some people at Microsoft, but why?  That would probably take forever to hear back from them and even get to someone who could actually point me in the right direction.

The next choice was to utilize resharper, it has a plugin model.  Some partially usable samples and a little documentation.  The documentation provided by Jetbrains although terribly lacking.. is much better than the non-existent samples for visual studio.  The springboard that made this really work for me was being able to look through an existing open source resharper plugin.  By looking through an existing (non trivial) plugin I was able to piece together what I want to do. 

What does it do?

The plugin adds some additional menu items to the Context Action menu for classes that are located in a file with additional classes.  The menus add an option to copy the class into a new file with a name of the type and than move it into a project that is referenced by the unit test project. While this solution realistically can only save 30-60 seconds of actual work, what it really does is eliminate the mental stress of doing the right thing and moving the class under test into the correct place in the solution so that you can keep focus on the test and design of the class under test.

Where can I get it?

The Resharper TDD Productivity plugin for resharper is located here: http://code.google.com/p/resharper-tdd-productivity-plugin/wiki/Features  It is an open source project and I welcome comments on how to make this plugin better. To download the latest version (works with resharper 4.1) download and run the installer from here: http://resharper-tdd-productivity-plugin.googlecode.com/svn/trunk/LatestVersion/TddProductivity.Setup.msi

What are the little inefficiencies that bother you?  Shoot me an email, send me a patch,  or just comment on this post. 

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Eric Hexter

I am the CTO for QuarterSpot. I (co)Founded MvcContrib, Should, Solution Factory, and Pstrami open source projects. I have co-authored MVC 2 in Action, MVC3 in Action, and MVC 4 in Action. I co-founded online events like mvcConf, aspConf, and Community for MVC. I am also a Microsoft MVP in ASP.Net.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://codingly.com Romain Verdier

    That is a nice idea.

    Btw, the installer asks for .NET 3.5 framework. I’m working with VS 2005 + R# 4.1, on a .NET 2.0 environment. Is it possible to use you addin in theses conditions ?

    Thanks.

  • Jason Imison

    This would be really useful if it could move methods to either an existing or a new file rather than whole classes. Then I could extract method followed by a move method during refactoring.

  • http://tobin@tobinharris.com Tobin Harris

    Great idea. I have exactly the same problem so this should be a nice solution. I didn’t even think about ReSharper plugins, that’s brill.

  • http://colinjack.blogspot.com Colin Jack

    Haven’t tried it out yet but this is a great idea, I work exactly the same way and can definitely see this saving me time. Great work.

  • Reddy

    Awesome solution.

    I normally move type to another file using Resharper shortcut ‘F6′ and then move the file to the project it belongs.

    Your solution is simple great.

  • Raif Harik

    Good for you for digging into the resharper plugin code! And this particular feature has always been something I’ve longed for. This is great.

  • http://robinclowers.blogspot.com Robin Clowers

    This is very cool, I think this plugin has a lot of potential to speed up the tdd cycle. Thanks Eric!

  • Thomas Eyde

    Latest R# has a quickfix for moving class to matching filename. However, one way or the other, I have to move the files to their proper folders/namespaces.

    What I miss, is a feature to move all classes in a folder to the matching namespace.

  • http://www.elegantcode.com Chris Brandsma

    Very cool. thank you for releasing this.

  • Stefan

    Seems to just crash VS2008 running resharper 4.1 :( anyone else having issues with this?

  • http://blogs.dovetailsoftware.com/blogs/kmiller Kevin Miller

    Great job Eric. This is already coming in very handy.

  • http://hex.lostechies.com erichexter

    @Stefan, email me the details around what source control or other plugins that you are running in visual studio. You can contact me at eric.hexter (at) gmail (dot) com.

    @Romain This should work in vs2005. I have not tried it yet but it should work, as long as you are running R# 4.1