7

How to replace MSTest with NUnit (C#)?

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

This is incomplete. If users use certain features (such as testing private and internal members via MSTest, they have to remove those test cases.
There's also a good chance that developers might want/need to install the nunit test adapter so they can continue to run tests from within visual studio.
Good point, but I have ReSharper which contais support for NUnit, so it's not included in my list. What test adapter would you recommend? I can add it as optional step to make this list complete...
also need to add "NUnit3TestAdapter" package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.