NUnit VS Adapter 2没有找到我的测试

时间:2015-12-28 10:01:15

标签: c# nunit

也许有人与Nunit测试有同样的问题。我已经下载了Nunit和Nunit适配器,我编写了一些代码和几个单元测试,但它说:

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

也许你可以告诉我一些想法,如何解决它?

我阅读了一些教程,它说我应该使用测试资源管理器,它会自动集成我的测试。但没有任何反应,也许问题在于我使用3.0.1版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;
        }
    }
}

试验:

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);
        }
    }
}

软件包:

<?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>

1 个答案:

答案 0 :(得分:3)

如果您使用的是Nunit 3,则必须使用NuGet中可用的适当测试适配器NUnit3TestAdapter

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

请注意,它目前仍处于预发布状态,因此您必须打开NuGet Manager GUI中的“Include pre-releases”复选框以查看它或在程序包管理器控制台中使用–IncludePrerelease选项。