The other day I was “blessed with” the opportunity of porting a nUnit based test project to Microsoft Test.  Why would anyone do that?
Well, in my case it was the easiest as the test project was involved in Microsoft TFS CI build process that was using Microsoft Test.

So how do you actually do that?

Step 1:  Make Visual Studio recognize the project as being a test project – instead of just a “normal” class library.  you can see if your project is a test project when you try to add items to the project.  In a Microsoft test project, you can when right-clicking the project in the solution explorer and choosing “Add” see the menu item “New Test…”.   However in a normal class library you will not see this item – hence the classlibrary is not a Microsoft Test project.

I had to do a little bit of hacking here, manually editing the project file in a text-editor (e.g. Notepad++).

Here I inserted the line:



As shown in my project file here:


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <UpgradeBackupLocation />
    <TargetFrameworkProfile />

Now reloading the project and the project was now recognized as a Microsoft Test project.

Step 2: Add a reference to the Microsoft.VisualStudio.TestTools.UnitTesting assembly.

Step 3: Remove all references to nUnit assemblies

using Resharper made it quite simple to spot the errors/indifferences and correct them.   Microsoft Test uses a slightly different “test-dialect” (attributes/asserts).
Making it necessary to:

Replace all [TestFixture] attributes with the [TestClass] attribute and on each test method replacing the [Test] attribute with the [TestMethod] attribute.
Further more I had to change some of my negative tests, where I was using the [ExpectedException] attribute that in nUnit gives the opportunity of testing the actual exception message – which isn’t possible in the Microsoft Test dialect.

Other minor changes I had to do was e.g. to change:



to the less-readable (but Microsoft Test compatible) construct:


… and that was basically it – I’d converted my nUnit project to a Microsoft Test project.  Here’s a little quick-reference of the differences between the nUnit and Microsoft attributes:

nUnit Microsoft Test
[TestFixture] [TestClass]
[Test] [TestMethod]
[Setup] [TestInitialize]
[TearDown] [TestCleanup]
[TestFixtureSetup] [ClassInitialize]
[TestFixtureTearDown] [ClassCleanup]

If you have to choose between nUnit and Microsoft Test, I personally am in favor of nUnit.  nUnit provides more logical naming (but I guess that’s just a habbit) but also better and shorter constructions for tests.   In my case there was however no choice in doing the conversion to Microsoft Test.