如果你想在一個控制檯模式打開,添加NUnit控制檯-runner.dll參考和使用:
NUnit.ConsoleRunner.Runner.Main(new string[]
{
System.Reflection.Assembly.GetExecutingAssembly().Location,
});
如果你想在一個GUI模式開,加NUnit的 - 桂 - runner.dll參考和使用:
NUnit.Gui.AppEntry.Main(new string[]
{
System.Reflection.Assembly.GetExecutingAssembly().Location,
"/run"
});
這是最好的方法,因爲你不甲肝e指定任何路徑。
另一種選擇也是NUnit的亞軍在Visual Studio調試器輸出整合:
public static void Main()
{
var assembly = Assembly.GetExecutingAssembly().FullName;
new TextUI (new DebugTextWriter()).Execute(new[] { assembly, "-wait" });
}
public class DebugTextWriter : StreamWriter
{
public DebugTextWriter()
: base(new DebugOutStream(), Encoding.Unicode, 1024)
{
this.AutoFlush = true;
}
class DebugOutStream : Stream
{
public override void Write(byte[] buffer, int offset, int count)
{
Debug.Write(Encoding.Unicode.GetString(buffer, offset, count));
}
public override bool CanRead { get { return false; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override void Flush() { Debug.Flush(); }
public override long Length { get { throw new InvalidOperationException(); } }
public override int Read(byte[] buffer, int offset, int count) { throw new InvalidOperationException(); }
public override long Seek(long offset, SeekOrigin origin) { throw new InvalidOperationException(); }
public override void SetLength(long value) { throw new InvalidOperationException(); }
public override long Position
{
get { throw new InvalidOperationException(); }
set { throw new InvalidOperationException(); }
}
};
}
在結束我的解決方案是隻使用的xUnit。 NUnit有點笨重。 – 2011-09-20 00:51:43