C# 使用mono/nunit console/4在Mac OS X控制台上运行测试
我安装了Max OS X 10.11.1,上面有Xamarin。我编写了简单的测试类,只是为了测试在Mac OS X和Ubuntu上运行Nunit测试,该类有一个返回字符串的方法:C# 使用mono/nunit console/4在Mac OS X控制台上运行测试,c#,macos,mono,nunit,nunit-console,C#,Macos,Mono,Nunit,Nunit Console,我安装了Max OS X 10.11.1,上面有Xamarin。我编写了简单的测试类,只是为了测试在Mac OS X和Ubuntu上运行Nunit测试,该类有一个返回字符串的方法: using System; namespace testing_project { public class EmptyClass { public EmptyClass () { } static void Main(string[
using System;
namespace testing_project
{
public class EmptyClass
{
public EmptyClass ()
{
}
static void Main(string[] args)
{
}
public string helloWorld()
{
return "Hello World!";
}
}
}
我有一个NUnit类来测试我的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中运行此测试时,测试通过得很好
如何在CLI上实现这一点?Mono包括NUnit runner/console(版本2.4.8)的安装,该安装通过名为
NUnit console的shell脚本调用:
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/程序集:
MONO_IOMAP=all nunit-console nunit-lib/nunit-lib.csproj
或
注意:NUnit console 2.4.x因硬编码的Windows样式目录分隔符而损坏。在解析.csproj文件并创建预期的CIL/程序集位置时,请使用MONO\u IOMAP
解决此问题。这在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控制台--帮助
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.
绝对正确!如果我能再给你100分。非常感谢你!哈哈,我再多喝点咖啡;-)
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.