Convert MsTest to NUnit

AngleSharp has used MsTest for a while, but due to some reasons a change seemed necessary.

Unfortunately the standard framework in Visual Studio 2013 for doing unit testing is still MsTest. Even though I liked MsTest for some reasons it has been time to change. There are two important reasons:

  • MonoDevelop does not support MsTest
  • Microsoft does not use it any more and there haven't been any updates for a while

Some small projects may have no problem with MsTest, but AngleSharp for instance is an open-source project that aims to be developed (and used / tested) by developers, regardless of their IDE or operating system. Therefore NUnit seems like a superior choice.

We should also not forget that NUnit has a lot more assertations and helpers than MsTest. And finally it does not require any special kind of project type. It only requires a reference to the framework and corresponding attributes on classes and methods. That's it!

Converting AngleSharp has therefore as easy as the following steps:

  1. Installing the NuGet package of NUnit to the test library
  2. Simple search and replace of:
    • [TestClass] to [TestFixture]
    • [TestMethod] to [Test]
    • [TestInitialize] to [SetUp]
    • [TestCleanup] to [TearDown]
    • [TestClassInitialize] to [TestFixtureSetUp]
    • [TestClassCleanup] to [TestFixtureTearDown]
    • using Microsoft.VisualStudio.TestTools.UnitTesting; to using NUnit.Framework;
  3. A regular expression powered search and replace using
    Assert.IsInstanceOfType\(([0-9A-Z-az\[\]\.\(\)]+), typeof\((\w+)\)\);
    
    with
    Assert.IsInstanceOf<$2>($1);
    
    There may be special cases that are not covered by the latter (like calling methods with multiple arguments), but these should be occurring quite rarely.
  4. Installing the NuGet package of NUnitTestAdapter to integrate with the test explorer

And that's it. It also makes sense to dereference the MsTest framework, as it is not (and should not be) used any more.

Created .

References

Sharing is caring!