Today one of my customers decide to work with MSTest Unit Test instead of NUnit, he asked me what he need to do to make it happen?
There are couple of options to accomplish that”:
- Add Build Extension to Support NUnit run from MSBuild.
- Create Custom Activity to run NUnit executable
- Convert the NUnit Syntax to MSBuild
Because the customer had nothing special in NUnit and the entire company works in .NET and Team Build we decide to convert the NUnit Tests to MBuild Unit Tests Format.
Here is the steps you need to do:
You need to change “Nunit.framework.dll” with “Microsoft.VisualStudio.QualityTools.UnitTestFramework”.
And change the using from “using NUnit.Framework;” with “using Microsoft.VisualStudio.TestTools.UnitTesting;”.
You need to change NUnit attributes to MSTest by the following list:
- [TestFixture] -> [TestClass]
- [Test] -> [TestMethod]
- [SetUp] -> [TestInitialize]
- [TearDown] -> [TestCleanup]
- [TestFixtureSetUp] -> [ClassInitialize]
- [TestFixtureTearDown] -> [ClassCleanup]
Most of the assertions methods in NUnit are the same as NUnit by name but some will require you to change it manually for example:
- Assert.Less(x,y) to Assert.IsTrue(x < y)
- Assert.Greater(x, y) to Assert.IsTrue(x > y)