如何在 Visual Studio 2015 上使用 NuGet 包管理器为 C# 安装 NUnit
How to install NUnit for C# with NuGet Package Manager on Visual Studio 2015
我有 Visual Studio 2015。我想使用 NuGet 包管理器为 C# 项目添加 NUnit 测试,并且我希望有可能使用 Visual Studio 进行 运行ning 测试并在Visual Studio.
首先我创建新的 C# 项目:
菜单 文件 → 新建 → 项目 → 已安装 → 模板 → Visual C# → 控制台应用程序 → OK.
然后我安装NUnit:
菜单 工具 → NuGet 包管理器 → 管理解决方案的 NuGet 包... 然后我安装包:
- N单位
- 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.
我下一步要做的是使用代码添加新的 class:
右键单击项目 → Add → Class → Visual C# Items → Class
名称 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 版本,看看是否有所不同。
我遇到了同样的问题,我的同事通过安装解决了这个问题:
我有 Visual Studio 2015。我想使用 NuGet 包管理器为 C# 项目添加 NUnit 测试,并且我希望有可能使用 Visual Studio 进行 运行ning 测试并在Visual Studio.
首先我创建新的 C# 项目: 菜单 文件 → 新建 → 项目 → 已安装 → 模板 → Visual C# → 控制台应用程序 → OK.
然后我安装NUnit: 菜单 工具 → NuGet 包管理器 → 管理解决方案的 NuGet 包... 然后我安装包:
- N单位
- 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.
我下一步要做的是使用代码添加新的 class: 右键单击项目 → Add → Class → Visual C# Items → Class 名称 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 版本,看看是否有所不同。
我遇到了同样的问题,我的同事通过安装解决了这个问题: