Showing posts with label guidelines. Show all posts
Showing posts with label guidelines. Show all posts

08 July 2009

Migrating Source -- Switching Unit Testing Framework

I noticed several people are migrating their source code base from NUnit to MSTest and vice versa. I thought I could share a useful technique to automate this process with ReSharper, and it appears to be large enough topic to not fit my my twitter feed. Obviously, it applies not just to Unit Testing Framework switching, but to almost any library migrations.

If I were faced with the task to migrate NUnit to MSTest I wouldn't use search-and-replace, but instead migrate it via temporary stubs. It would require me do several pretty easy steps:
  1. Remove references to nuint.framework.dll. I will get lots of red code, but we'll fix it in a minute.

  2. Add nunit.framework.dll source code to solution (if permitted by license), or write stubs for what I use, like TestFixture, Test, Setup and TearDown attributes and assertion classes. When I'm done with that, all code should be green again, which you can instantly verify with Solution Wide Analysis.

  3. Move all those types to MSTest namespaces.

  4. Rename types to match MSTest types.

  5. For assertions, implement missing members using existing API and use Inline Method refactoring to get rid of them.

  6. Remove stubs and add references to MSTest assemblies.

  7. Enjoy MSTest runner in ReSharper 4.5 to run your beloved tests.



Using this technique, or variation of it, you can easily migrate your source code to different API, library or technology, even if you don't have source code for it.

Develop with pleasure!

03 October 2008

ReSharper Guidelines -- First Time Users

Harry L. wrote in review of ReSharper on Visual Studio Gallery:
... I have found that I used the features of Resharper almost without knowing it. What amazed me was how many features I use without going up a long learning curve...

Indeed, most important ReSharper features can be instantly learned right from the code editor without reading any documentation. However, I thought that having some guidelines about where to look and how to improve own productivity would be nice anyway. So I'm going to write several posts about how to use ReSharper in a form of guidelines.

Shortcuts are given for Visual Studio keyboard scheme, but you can easily find shortcuts for your configuration in ReSharper menu.

First Time Users guidelines:


  1. DO open your real project in Visual Studio with ReSharper enabled. Playing with the productivity tool in a sandbox doesn't really give you understanding about its effect. It can take some time for ReSharper to analyze your solution for the first time, but it will be much faster during subsequent runs.

  2. DO NOT run away from your Visual Studio when you first open your source code with ReSharper :) You will see colored identifiers, a lot of squiggles indicating warnings and suggestions, redundant code painted in gray -- your code most likely will be overhighlighted. You will clean it up pretty fast with ReSharper. You can switch Color Identifiers off if you wish (ReSharper / Options / Code Inspection / Settings).

  3. DO configure your naming (ReSharper / Options / Languages / Common / Naming Style) and formatting preferences (ReSharper / Options / Languages / C# / Formatting Style). ReSharper uses these settings when guessing on identifiers, while updating the code and doing other automatic code generation and transformation for you.

  4. DO learn 4 keyboard shortcuts to use in code editor:

    • Alt-Enter - opens code transformation menu with Quick Fixes and Context Actions. Try it whenever you see light bulb to the left of your code, and see what you can do with it.
    • Alt-` (Navigate from Here) to open menu with actions to navigate from currently selected symbol, like "Go to base", "Go to derived" and "Go to usages"
    • Alt-Ins (Generate) -- generates type members, like properties, constructors, overrides and implementations, Equals, GetHashCode and ToString methods.
    • Ctrl-Shift-R (Refactor This) -- opens menu with all refactorings available at current caret position (or current selection in any ReSharper tool window).

  5. DO NOT use Solution Explorer to find code, use "Go to Type" (Ctrl-T), "Go to File" (Ctrl-Shift-T), "Recent Files" (Ctrl-,) and other commands from ReSharper / Go To menu. This will help you navigate much faster.


After you familiarize yourself with these basic actions, download and print key map and start exploring other commands.