Art Of Programming

musings by Dmytrii Nagirniak

From MsTest to NUnit

That’s pretty easy to switch from MsTest to NUnit (or other xUnit framework, but I’ve decided I want NUnit). You need to do following steps:
  1. Change the Visual Studio project type:

    1. Unload the project with tests.
    2. Remove <ProjectTypeGuids> node from there.
    3. Save and reload the project.

  2. Replace Reference from MsTest to your xUnit.
  3. Replace using statements (Remove Microsoft.VisualStudio.TestTools.UnitTesting, add NUnit.Framework and optionally NUnit.Framework.SyntaxHelpers).
  4. Replace (just use Find and Replace in Files) [TestClass] to [TestFixture].
  5. Replace [TestMethod] to [Test].
  6. Replace [TestInitialize] to [SetUp].
  7. Replace [TestCleanup] to [TearDown]
  8. Now you should be able to compile the tests.
  9. Clean all the stuff from MsTest (TestResults folder, Solution Items that describe test data).
Pretty easy.
The note is (if you don’t know) that there’s no build-in runner for Visual Studio (unlike MsTes), so you’ll need to run tests:
  1. from outside of Visual Studio by GUI runner
  2. using TestDriven.NET
  3. using ReSharper.
That’s it. I’m back with old good NUnit.

Comments

kit
Very handy, thanks :)

Comments