How to replace MSTest with NUnit (C#)?
1 Answer
Add nuget package NUnit package into test project
Install-Package NUnitRemove 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.InconclusiveUnload 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.
4 Comments
Lex Li
This is incomplete. If users use certain features (such as testing private and internal members via MSTest, they have to remove those test cases.
forsvarir
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.
Tomino
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...
Jaydeepsinh
also need to add "NUnit3TestAdapter" package.