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. 


Posted Oct 07 2008, 09:28 PM by erichexter

Comments

Reflective Perspective - Chris Alcock » The Morning Brew #196 wrote Reflective Perspective - Chris Alcock » The Morning Brew #196
on 10-08-2008 2:23 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #196

Romain Verdier wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 3:08 AM

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 wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 3:19 AM

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.

Tobin Harris wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 3:47 AM

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.

Colin Jack wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 7:13 AM

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.

Dew Drop - October 8, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - October 8, 2008 | Alvin Ashcraft's Morning Dew
on 10-08-2008 7:36 AM

Pingback from  Dew Drop - October 8, 2008 | Alvin Ashcraft's Morning Dew

Arjan`s World » LINKBLOG for October 8, 2008 wrote Arjan`s World » LINKBLOG for October 8, 2008
on 10-08-2008 8:37 AM

Pingback from  Arjan`s World    » LINKBLOG for October 8, 2008

Reddy wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 10:02 AM

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 wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 11:10 AM

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.

Robin Clowers wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 11:40 AM

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

Thomas Eyde wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 11:56 AM

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.

Chris Brandsma wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 12:15 PM

Very cool. thank you for releasing this.

Stefan wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-08-2008 10:47 PM

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

Kevin Miller wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-09-2008 7:19 AM

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

erichexter wrote re: Announcing the Test Driven Development Productivity Plugin for Resharper
on 10-09-2008 3:28 PM

@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

Copyright Los Techies 2007, 2008. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems