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!

3 comments:

Bruno said...

Nice refactoring trick. I wonder if the "quick fix" that is used to rename broken symbols could be used on a solution wide scale in the future. That could help in this case, since when you remove the references and the symbols no longer exist you could "find and replace" on the entire solution

Anonymous said...

This is very helpful. Also, thank you very much for the outstanding and timely VS2010 support!!

Andrew said...

Helping people to migrate from one mocking framework to another (Rhino Mocks to Moq, NMock2 to Isolator, etc) might be an interesting and challenging task too :)