Pr0t3
Pr0t3

Reputation: 37

NUnit VS Adapter 2 is not finding my tests

Maybe someone have had same problems with Nunit testing. I have downloaded Nunit and Nunit adapter, I write some code and few unit tests, but it says:

NUnit VS Adapter 2.0.0.0 discovering test is finished
========== Discover test finished: 0 found (0:00:00,4917596) ==========

Maybe you could tell me some ideas, how to fix it?

I read few tutorials it says I should use test explorer, and it automatically integrates my test. But nothing happens, maybe problem is in that I use 3.0.1 version Nunit?

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter two numbers\n");
            int number1;
            int number2;
            number1 = int.Parse(Console.ReadLine());
            number2 = int.Parse(Console.ReadLine());

            MathsHelper helper = new MathsHelper();
            int x = helper.Add(number1, number2);
            Console.WriteLine("\nThe sum of " + number1 +
                " and " + number2 + " is " + x);
            Console.ReadKey();
            int y = helper.Subtract(number1, number2);
            Console.WriteLine("\nThe difference between " +
                  number1 + " and" + number2 + "  is " + y);
            Console.ReadKey();
        }
    }

    public class MathsHelper
    {
        public MathsHelper() { }
        public int Add(int a, int b)
        {
            int x = a + b;
            return x;
        }

        public int Subtract(int a, int b)
        {
            int x = a - b;
            return x;
        }
    }
}

Tests:

using NUnit.Framework;

namespace ConsoleApplication16
{
    [TestFixture]
    public class TestClass
    {
        [TestCase]
        public void AddTest()
        {
            MathsHelper helper = new MathsHelper();
            int result = helper.Add(20, 10);
            Assert.AreEqual(30, result);
        }

        [TestCase]
        public void SubtractTest()
        {
            MathsHelper helper = new MathsHelper();
            int result = helper.Subtract(20, 10);
            Assert.AreEqual(10, result);
        }
    }
}

packages:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NUnit" version="3.0.1" targetFramework="net452" />
  <package id="NUnitTestAdapter" version="2.0.0" targetFramework="net452" />
</packages>

Upvotes: 1

Views: 1235

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26876

If you're using Nunit 3, you have to use appropriate test adapter available in NuGet as NUnit3TestAdapter.

<packages>
  <package id="NUnit" version="3.0.1" targetFramework="net452" />
  <package id="NUnit3TestAdapter" version="3.0.8-ctp-8" targetFramework="net452" />
</packages>

Notice it is still in pre-release at present time, so you have to turn on "Include pre-releases" checkbox in NuGet Manager GUI to see it or use –IncludePrerelease option in package manager console.

Upvotes: 3

Related Questions