使用 mono/nunit-console/4 在 Mac OS X 控制台上运行测试

Running tests on Mac OS X console using mono/nunit-console/4(使用 mono/nunit-console/4 在 Mac OS X 控制台上运行测试)
本文介绍了使用 mono/nunit-console/4 在 Mac OS X 控制台上运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 Max OS X 10.11.1,上面装有 Xamarin.我写了简单的测试类,只是为了测试在 Mac OS X & 上运行的 Nunit 测试.Ubuntu,类实际上有一个返回字符串的方法:

I have Max OS X 10.11.1 installed, with Xamarin on it. I wrote simple testing class, just to test running Nunit tests on Mac OS X & Ubuntu, class has literally one method which returns string:

using System;

namespace testing_project
{
    public class EmptyClass
    {
        public EmptyClass ()
        {
        }

        static void Main(string[] args)
        {
        }

        public string helloWorld()
        {
            return "Hello World!";
        }
    }
}

我有一个 NUnit 类来测试我的 EmptyClass:

And I have a NUnit class to test my EmptyClass:

using System;
using NUnit.Framework;

namespace testing_project
{
    [TestFixture]
    public class EmptyClassTest
    {
        [Test]
        public void testHelloWorld()
        {
            EmptyClass empty = new EmptyClass();
            Assert.AreEqual ("Hello World!", empty.helloWorld ());
        }
    }
}

当我在 Xamarin Studio 中运行它时,测试通过就好了.

When I run this in Xamarin studio, test is passing just fine.

如何在 CLI 上实现这一点?

How can I achieve this on CLI?

推荐答案

Mono 包含一个安装 NUnit 的运行器/控制台(版本 2.4.8),它通过名为 nunit-console 的 shell 脚本调用:

Mono includes an install of NUnit's runner/console (version 2.4.8) that is called via a shell script called nunit-console:

cat `which nunit-console`
#!/bin/sh
exec /Library/Frameworks/Mono.framework/Versions/4.2.1/bin/mono --debug $MONO_OPTIONS /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/4.5/nunit-console.exe "$@"

因此,要从 CLI 运行测试,您可以调用 NUnit 的测试 .csproj 或 CIL/Assembly:

So to run your tests from the CLI you can either call the NUnit's test .csproj or the CIL/Assembly:

MONO_IOMAP=all nunit-console nunit-lib/nunit-lib.csproj

nunit-console nunit-lib/bin/Debug/nunit-lib.dll

注意:在解析 .csproj 文件和创建预期的 CIL/程序集位置时,由于硬编码的 Windows 样式的目录分隔符导致 NUnit 控制台 2.4.x 损坏,请使用 MONO_IOMAP 来解决它.这在 NUnit runner 3.0 中不是问题.

NOTE: NUnit console 2.4.x is broken due a hard-coded Windows-style Directory Separator when parsing .csproj files and creating the expected CIL/assembly location, use MONO_IOMAP to work around it. This is not a issue in NUnit runner 3.0.

示例:

nunit-console nunit-lib/bin/Debug/nunit-lib.dll

NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Unix 15.0.0.0
  CLR Version: 4.0.30319.17020 ( 4.2.1 (explicit/8862921 Thu Oct 29 17:09:16 EDT 2015) )

.F
Tests run: 1, Failures: 1, Not run: 0, Time: 0.687 seconds

Test Case Failures:
1) nunitlib.Test.TestCase :   Expected string length 8 but was 5. Strings differ at index 0.
  Expected: "Overflow"
  But was:  "Stack"
  -----------^

nunit-console --help

NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Unix 15.0.0.0
  CLR Version: 4.0.30319.17020 ( 4.2.1 (explicit/8862921 Thu Oct 29 17:09:16 EDT 2015) )


NUNIT-CONSOLE [inputfiles] [options]

Runs a set of NUnit tests from the console.

You may specify one or more assemblies or a single
project file of type .nunit.

Options:
-fixture=STR            Test fixture to be loaded (Short format: -load=STR)
-run=STR                Name of the test to run
-config=STR             Project configuration to load
-xml=STR                Name of XML output file
-transform=STR          Name of transform file
-xmlConsole             Display XML to the console
-output=STR             File to receive test output (Short format: -out=STR)
-err=STR                File to receive test error output
-labels                 Label each test in stdOut
-include=STR            List of categories to include
-exclude=STR            List of categories to exclude
-domain=X               AppDomain Usage for Tests
-noshadow               Disable shadow copy when running in separate domain
-nothread               Disable use of a separate thread for tests
-wait                   Wait for input before closing console window
-nologo                 Do not display the logo
-nodots                 Do not display progress
-help                   Display help (Short format: -?)


Options that take values may use an equal sign, a colon
or a space to separate the option from its value.

这篇关于使用 mono/nunit-console/4 在 Mac OS X 控制台上运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)