Converting MSTest Assemblies to NUnit

If you wanted to convert existing test assemblies for a Visual Studio solution from using MSTest to NUnit, how would you do it?  This post will provide one answer to that question.

I started by changing the type of the test assembly.  To do this, I opened the .proj file with a text editor, then used this link to find the MSTest GUID in the file and remove it (the guid will be inside a ProjectTypeGuids XML tag).  This should ensure that Visual Studio and/or any third-party test runners can identify it correctly.  Once I saved that change, the remaining steps were:

  • replace references to Microsoft.VisualStudio.QualityTools.UnitTestFramework with nunit.framework
  • change unit test attributes from MSTest to NUnit (you may find a side-by-side comparison helpful)
  • delete any code specific to MSTest (this includes TestContext, DeploymentItem, AssemblyInitialize, AssemblyCleanup, etc)

After the above steps, NUnit ran the tests without any further modifications.  All of my calls to Assert worked the same way in NUnit that they did in MSTest.