2015-11-20 17 views
6

Tôi đã cài đặt Max OS X 10.11.1, với Xamarin trên đó. Tôi đã viết lớp thử nghiệm đơn giản, chỉ cần để kiểm tra chạy thử nghiệm Nunit trên Mac OS X & Ubuntu, lớp có nghĩa là một phương pháp mà trả về chuỗi:Chạy thử nghiệm trên bảng điều khiển Mac OS X bằng cách sử dụng đơn/nunit-console/4

using System; 

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

     static void Main(string[] args) 
     { 
     } 

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

Và tôi có một lớp NUnit để kiểm tra EmptyClass tôi:

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()); 
     } 
    } 
} 

Khi tôi chạy chương trình này trong Xamarin studio, bài kiểm tra đã trôi qua tốt.

Làm thế nào tôi có thể đạt được điều này trên CLI?

Trả lời

12

Mono bao gồm một cài đặt của NUnit của Á hậu/console (phiên bản 2.4.8) được gọi là thông qua một kịch bản shell gọi 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 "[email protected]" 

Vì vậy, để chạy thử nghiệm của bạn từ CLI bạn có thể gọi của NUnit kiểm tra .csproj hoặc CIL/hội:

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

hoặc

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

CHÚ Ý: Bảng điều khiển NUnit 2.4.x bị hỏng do Bộ phân tách thư mục kiểu Windows được mã hóa cứng khi phân tích tệp .csproj và tạo vị trí CIL/assembly dự kiến, sử dụng MONO_IOMAP để làm việc xung quanh nó. Đây không phải là một vấn đề trong NUnit runner 3.0.

Ví dụ:

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. 
+1

Tuyệt đối tại chỗ trên! Nếu tôi có thể cho bạn 100 điểm nữa. Cảm ơn nhiều! –

+1

LOL, tôi sẽ chỉ uống thêm cà phê ;-) – SushiHangover

Các vấn đề liên quan