May 182011


Fortunately, this is really a very simple step (or at least in our case it was):

  1. Remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework and replace it with a reference to nunit.framework. If you use nuget, you can add a library reference to the NUnit package.
  2. You need to do some search & replace in all files. The table below illustrates what to search for and what to replace it with:
    Search (MSUnit code) Replace with (NUnit code)
    using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework;
    [TestClass] [TestFixture]
    [TestMethod] [Test]
    [TestInitialize] [SetUp]
    [TestCleanup] [TearDown]
    [ClassInitialize] [TestFixtureSetUp]
    [ClassCleanup] [TestFixtureTearDown]
  3. At this step you should be almost done. One of the issues I had with the code is that I used in several places the Assert.IsInstanceOfType assertion. It seems that the NUnit assertion expects arguments in the opposite order than MSUnit. Also there is a generic Assert.IsInstanceOf<> method that you can use. I’ve made a search and replace regex that will fix most of these assertions in your code: imageFor convenience, the search expression is: Assert.IsInstanceOfType({[^,:b]+}:b*,:b*typeof({:i}));
    and the replace expression is: Assert.IsInstanceOf<2>(1);

    Also, make sure you have the two checkboxes checked.

  4. We also had some other errors in the tests, that required running the tests in a Single Threaded Apartment (STA) thread. To accomplish this, you need to decorate the test or the test method with the [RequiresSTA] attribute (check this link for more details:

At this stage you should be done with the migration of the test code. If there are any other issues you encounter, please let me know and I will update this blog post with the steps involved.


Check out the next parts of this series here: