Announcing the Test Driven Development Productivity Plugin for Resharper
Why does visual studio make doing the right thing, so hard to do?
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.
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.
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.