How to replace MSTest with NUnit (C#)?
The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.
NET 6.0 and we've stopped testing NUnit against . NET Core 2.1 which is now out of support. There are also several fixes for the new FixtureLifeCycle feature and other smaller bug fixes and performance improvements.
Navigate to Tools -> NuGet Package Manager -> Manager NuGet Packages for Solution. Search for NUnit & NUnit Test Adapter in the Browse tab. Click on Install and press OK to confirm the installation. With this installation, the NUnit framework can be used with C#.
Add nuget package NUnit package into test project
Install-Package NUnit
Remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework
Change the following namespace usings from
using Microsoft.VisualStudio.TestTools.UnitTesting;
to
using NUnit.Framework;
Search and replace the following:
[TestClass] => [TestFixture]
[ClassInitialize] => [TestFixtureSetUp]
[ClassCleanup] => [TestFixtureTearDown]
[TestInitialize] => [SetUp]
[TestCleanup] => [TearDown]
[TestMethod] => [Test]
Assert.Ignore => Assert.Inconclusive
Unload project, open the .csproj file as Xml and remove line that looks like:
<ProjectTypeGuids>{0b19334d-acce-4bf9-9475-088436fada27};{a9df11a7-84ef-49d2-b13a-9ed7e1f913e6}</ProjectTypeGuids>
Remove (or replace) private or internal modifiers and make sure the Test project has visibility to internal members. You can refer this link for InternalsVisibleTo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With