我有Visual Studio2015。我想使用NuGet软件包管理器为C#项目添加NUnit的测试,并且希望可以在Visual Studio和Visual Studio中运行测试。
首先,我创建一个新的C#项目:菜单文件→新建→项目→已安装→模板→ Visual C# →控制台应用程序→ OK。
然后安装NUnit:菜单工具→ NuGet软件包管理器→管理解决方案的NuGet软件包...然后安装软件包:
在输出中,我看到:
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.
我要做的下一步是使用代码添加新类:右键单击项目→添加→类→ Visual C#项目→类名称Tests.cs →添加
然后我使用下面的代码:
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class Tests
{
[Test]
public void t1()
{
}
[Test]
public void t2()
{
}
}
}
最后,当我在Test Explorer上按RunAll时,我看到:
------ 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.
奇怪的是,当有人使用NuGet在Visual Studio 2015中安装NUnit并在Visual Studio中运行测试时,我没有找到任何教程。
您似乎正在使用NUnit 3 Beta。从错误消息中,我猜想测试运行程序不支持它。尝试将NUnit软件包更改为2.x版本,看看是否有区别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句