Domanda

I'm trying to create unit tests with resharper, but every time I click "create unit tests" it imports Microsoft.VisualStudio.QualityTools.UnitTestFramework and create MS unit tests. There is no option to use NUnit instead.

  • I've disabled VisualStudio Testing Support in Resharper
  • I deleted the MS UnitTest reference, but NUnit does not appear as a reference in the "Add reference" dialog
  • I've manually added NUnit to my tests project with NuGet
  • Resharper STILL uses VisualStudio's unit tests and imports the other DLL

Also,

  • Resharper's website mostly talks about running tests, I do not have any tests yet
  • I've tried searching but I seem to find information about how to run tests

So, if I have a class library. What are the exact steps I need to take to get Resharper to automatically create NUnit tests? I'm new to NUnit and fairly new to ReSharper so what am I missing?

È stato utile?

Soluzione

To use NUnit unit tests do the following:

  • Add a Visual Studio C# Class Library project (don't use the Unit Test projects as they are designed to work with MSTest)
  • Add NUnit references via NuGet

An example of the class structure will be:

using NUnit.Framework

namespace MyTest.Tests
{
    [TestFixture]
    public void MyTests
    {
        [Test]
        UnitUnderTest_Scenario_ExpectedBehaviour()
        {
            // Test code goes here.
        }
    }
}

Resharper will decorate your tests with the green and yellow icons, see this and this for more details.

Update: See how Resharper can speed up the creation of unit tests.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top