Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace MSTest by NUnit (C#)

Tags:

c#

mstest

nunit

How to replace MSTest with NUnit (C#)?

like image 879
Tomino Avatar asked May 26 '15 07:05

Tomino


People also ask

Is NUnit better than MsTest?

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.

Does NUnit support .NET 6?

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.

How do I run a NUnit test in C#?

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#.


1 Answers

  1. Add nuget package NUnit package into test project

    Install-Package NUnit
    
  2. Remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework

  3. Change the following namespace usings from

    using Microsoft.VisualStudio.TestTools.UnitTesting; 
    

    to

    using NUnit.Framework;
    
  4. Search and replace the following:

    [TestClass] => [TestFixture]
    [ClassInitialize] => [TestFixtureSetUp]
    [ClassCleanup] => [TestFixtureTearDown]
    [TestInitialize] => [SetUp]
    [TestCleanup] => [TearDown]
    [TestMethod] => [Test]
    Assert.Ignore => Assert.Inconclusive
    
  5. 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>
    
  6. 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.

like image 95
Tomino Avatar answered Sep 30 '22 09:09

Tomino