【问题标题】:How to install NUnit for C# with NuGet Package Manager on Visual Studio 2015如何在 Visual Studio 2015 上使用 NuGet 包管理器安装 NUnit for C#
【发布时间】:2015-10-12 12:55:27
【问题描述】:

我有 Visual Studio 2015。我想使用 NuGet 包管理器为 C# 项目添加 NUnit 测试,并且我希望能够在 Visual Studio 和 Visual Studio 中运行测试。

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

  2. 然后我安装 NUnit: 菜单 ToolsNuGet Package ManagerManage 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.
    
  3. 我要做的下一步是使用代码添加新类: 右键单击项目 → 添加ClassVisual C# ItemsClass 名称 Tests.cs添加

    然后我使用下面的代码:

    namespace NUnit.Tests
    {
        using System;
        using NUnit.Framework;
    
        [TestFixture]
        public class Tests
        {
            [Test]
            public void t1()
            {
            }
            [Test]
            public void t2()
            {
            }
        }
    }
    
  4. 最后,当我在测试资源管理器上按 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 中运行测试时,我没有找到任何教程。

【问题讨论】:

标签: c# visual-studio-2015 nunit nuget-package


【解决方案1】:

看起来您正在使用 NUnit 3 beta。从错误消息中我猜测试运行程序不支持它。尝试将 NUnit 包更改为 2.x 版本,看看是否会有所不同。

【讨论】:

  • 成功了!!!我已安装非测试版 NUnit:“已成功将 'NUnit 2.6.4' 安装到 Tmp。”它发现了测试
  • 对于那些想知道如何在 VS2013 中安装 2.6.4 的人,由于 UI 只允许最新 (3+) 版本,请在包管理器控制台中运行:Install-Package NUnit -Version 2.6.4 -ProjectName <your project name>
  • 参考测试适配器 3 现已发布。安装包 NUnit3TestAdapter
【解决方案2】:

我遇到了同样的问题,我的同事通过安装解决了它:

NUnit3 Test Adapter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多