NUnit VS适配器2找不到我的测试
本文关键字:我的 测试 找不到 VS 适配器 NUnit | 更新日期: 2023-09-27 18:28:10
也许有人在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>
如果使用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中打开"包含预发布"复选框才能查看它,或者在包管理器控制台中使用–IncludePrerelease
选项。