Home > Cheat-sheet, development > Migrating from MSTest to NUnit

Migrating from MSTest to NUnit

March 28th, 2018

I am using VS2015 and VS2017 and I needed to migrate from Microsoft Unit tests to NUnit.

Those are the steps are followed.

  • In VS2015/2017 Select the “Package manager console” tab
    Select the correct project, (drop down combo), and type

  • Or using Nuget manager
    • Select the correct project.
    • Select NUnit, (just the plain ‘NUnit’ for now).
  • In your test project, look for “using Microsoft.VisualStudio.TestTools.UnitTesting;
    Replace with “using NUnit.Framework;“, (of course you will now have a whole bunch of errors.)
  • Look and replace
    • [TestClass] replace with [TestFixture]
    • [TestMethod] replace with [Test]
    • Remove code that looks like “[ExpectedException(typeof(xyz), “some text”)]” and surround the actual code that is expected to throw

NB: Note you might need to change a couple of other values

  • [TestInitialize] to [SetUp]
  • [TestCleanup] to [TearDown]
  • [TestClassInitialize] to [TestFixtureSetUp]
  • [TestClassCleanup] to [TestFixtureTearDown]

And a few other functions will need to change as well but for the most part they start with Assert.... and are fairly close(tm) to the Microsoft counterparts.

 

Comments are closed.