11

I have Visual Studio 2015. I want to add NUnit's tests for C# project with NuGet Package Manager, and I want to have possibility of running tests with Visual Studio and in Visual Studio.

  1. First I create new C# project: menu FileNewProjectInstalledTemplatesVisual C#Console ApplicationOK.

  2. Then I install NUnit: menu ToolsNuGet Package ManagerManage NuGet Packages for Solution... Then I install packages:

    • NUnit
    • NUnit.Runner
    • NUnitTestAdapter

    In the output I see:

    Successfully installed 'NUnit 3.0.0-beta-4' to Tmp.
    Successfully installed 'NUnit.Runners 2.6.4' to Tmp.
    Successfully installed 'NUnitTestAdapter 2.0.0' to Tmp.
    
  3. The next step I do is adding new class with code: Right click on project → AddClassVisual C# ItemsClass name Tests.csAdd

    Then I use below code:

    namespace NUnit.Tests
    {
        using System;
        using NUnit.Framework;
    
        [TestFixture]
        public class Tests
        {
            [Test]
            public void t1()
            {
            }
            [Test]
            public void t2()
            {
            }
        }
    }
    
  4. And finally when I press RunAll on Test Explorer I see:

    ------ Discover test started ------
    NUnit VS Adapter 2.0.0.0 discovering tests is started
    Attempt to load assembly with unsupported test framework in  C:\Users\Grzegorz\Desktop\Tmp\Tmp\bin\Debug\Tmp.exe
    NUnit VS Adapter 2.0.0.0 discovering test is finished
    ========== Discover test finished: 0 found (0:00:00,0720041) ==========
    
    No tests are being discovered.
    

The strange thing is that I found no tutorial when anybody uses NuGet to install NUnit in Visual Studio 2015 and run tests in Visual Studio.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
baziorek
  • 2,502
  • 2
  • 29
  • 43

2 Answers2

18

It looks like you are using NUnit 3 beta. From the error message I'd guess the test runner doesn't support it. Try changing the NUnit package to a 2.x version and see if that makes a difference.

Richard Matheson
  • 1,125
  • 10
  • 24
  • 1
    It worked!!! I've installed not beta NUnit: "Successfully installed 'NUnit 2.6.4' to Tmp." and it discovered tests – baziorek Oct 12 '15 at 16:14
  • 3
    For those wondering how to install 2.6.4 in VS2013, since the UI only allows the latest (3+) version, run this in the Package Manager Console: `Install-Package NUnit -Version 2.6.4 -ProjectName ` – makhdumi Jan 04 '16 at 22:46
  • 1
    For reference test adapter 3 has now been released. Install-Package NUnit3TestAdapter – niico May 09 '16 at 20:46
6

I had the same issue, and my colleague solved it by installing:

NUnit3 Test Adapter

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sunpochin
  • 328
  • 1
  • 4
  • 17