【发布时间】:2015-10-12 12:55:27
【问题描述】:
我有 Visual Studio 2015。我想使用 NuGet 包管理器为 C# 项目添加 NUnit 测试,并且我希望能够在 Visual Studio 和 Visual Studio 中运行测试。
首先我创建新的 C# 项目: 菜单 文件 → 新建 → 项目 → 已安装 → 模板 → Visual C# → 控制台应用程序 → OK.
-
然后我安装 NUnit: 菜单 Tools → NuGet Package Manager → Manage NuGet Packages for Solution... 然后我安装包:
- 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. -
我要做的下一步是使用代码添加新类: 右键单击项目 → 添加 → 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() { } } } -
最后,当我在测试资源管理器上按 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 和 NUnitTestAdapter。如何安装 NUnit.Runner?
标签: c# visual-studio-2015 nunit nuget-package