【问题标题】:Where is the DLL with test to run with the nunit3 console generated?与生成的 nunit3 控制台一起运行的带有测试的 DLL 在哪里?
【发布时间】:2018-09-28 17:11:56
【问题描述】:

我在 Visual Studio 中创建了一个项目,用于使用 nunit 的 nuget 包进行单元测试。该测试使用测试资源管理器在 Visual Studio 中运行良好,但我需要使用 nunit3 控制台运行它们。

我的项目很简单我:

  • 在 C# 中创建了一个控制台项目
  • 我使用 NuGet 包管理器安装了 Nunit 和 NUnitTestAdapter。
  • 我用下面的代码创建了一个名为 MyMath.cs 的类:

    namespace NunitDemo
    {
    class MyMath
    {
        public int add(int a, int b)
        {
            return a + b;
        }
    
        public int sub(int a, int b)
        {
            return a - b;
        }
    }
    }
    
  • 我使用以下代码创建了一个 MyTestCase 类来测试 MyMath 方法:

    using NUnit.Framework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace NunitDemo
    {
        [TestFixture]
        class MyTestCase
        {
            [TestCase]
            public void Add()
            {
               MyMath math = new MyMath();
               Assert.AreEqual(31, math.add(20, 11));
            }
    
            [TestCase]
            public void Sub()
            {
            MyMath math = new MyMath();
            Assert.AreEqual(9, math.sub(20, 11));
            }
        }
    }
    
  • 我重建了我的解决方案并使用测试资源管理器面板我可以在 Visual Studio 中毫无问题地运行我的测试。

但是我需要使用 nunit3-console 提示符运行我的测试,那么,我如何生成(或在哪里)一个 DLL 文件以使用 nunit-gui 从控制台运行测试?

我在 C:\Users\Manuel\source\repos\ConsoleAppForNunit\ConsoleAppForNunit\bin\Debug 内搜索,但没有合适的 .DLL

该路径有截图:

【问题讨论】:

    标签: c# unit-testing nunit nunit-console


    【解决方案1】:

    根据您的描述,您从未安装过 NUnit 控制台应用程序。你可以在各个地方找到它...

    1. 如果您使用 Chocolatey,请使用 choco 命令行实用程序安装 nunit-consolerunner。

    2. 如果您希望将其安装在项目目录中,请从 nuget.org 安装 NUnit.ConsoleRunner。您可以在 Visual Studio 中执行此操作。

    3. 您可以从项目站点https://github.com/nunit/nunit-console下载文件

    【讨论】:

    • 好吧,我实际上有 nunit3-console,就我而言,它位于 C:\Program Files (x86)\NUnit.org\nunit-console。
    • 在那种情况下,我不明白问题是什么。您显然使用.msi 文件将它安装在那里。为什么不直接使用呢?
    • 解决了将项目类型从控制台更改为类库项目的问题。稍后我会添加一个详细的解决方案。
    • NUnit3-console 可以运行包含在 dll 或 exe 中的测试。
    • @Charlie:谢谢,我提供了exe并且它能够执行,所以它不必是dll。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2012-10-18
    相关资源
    最近更新 更多