繁体   English   中英

如何在Visual Studio 2015上使用NuGet Package Manager安装NUnit for C#

[英]How to install NUnit for C# with NuGet Package Manager on Visual Studio 2015

我有Visual Studio 2015.我想用NuGet Package Manager为C#项目添加NUnit的测试,我希望有可能用Visual Studio和Visual Studio运行测试。

  1. 首先我创建新的C#项目:菜单文件新建项目已安装模板Visual C#控制台应用程序确定

  2. 然后我安装NUnit:菜单工具NuGet包管理器管理解决方案的NuGet包...然后我安装包:

    • NUnit的
    • NUnit.Runner
    • NUnitTestAdapter

    在输出中我看到:

     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. 我要做的下一步是添加带有代码的新类:右键单击项目→ 添加Visual C#项目类名称Tests.cs添加

    然后我使用下面的代码:

     namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture] public class Tests { [Test] public void t1() { } [Test] public void t2() { } } } 
  4. 最后,当我在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版本,看看是否有所作为。

我有同样的问题,我的同事通过安装解决了这个问题:

NUnit3测试适配器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM