NUintLite是簡化版的NUnit,可以應用于.NET Compact Framework,Mono等平台。
解壓源代碼,打開src\NUnitLiteCF目錄下的項目檔案,編譯生成NUnitLite.dll。
在使用NUnitLite的項目中添加對NUnitLite.dll的引用。在Main函數加入Test Runner

static void Main(string[] args)
{
System.IO.TextWriter writer = new System.IO.StreamWriter("\\Test\\TestResult.txt");
new NUnitLite.Runner.TextUI(writer).Execute(args);
writer.Close();
}

NUnitLite的Test Runner支援不同的輸出,TextUI輸出到檔案,ConsoleUI輸出到控制台(Console),DebugUI輸出Debug資訊,新版本還支援TcpUI把結果輸出通過TCP發送。

using NUnit.Framework;
[TestFixture]
class SqlCeHelperTest
{
private SqlCeHelper sqlCe = new SqlCeHelper();
[SetUp]
public void SetUp()
{
sqlCe.Open();
}
[TearDown]
public void TearDown()
sqlCe.Close();
[Test]
public void Test()
}

編寫測試案例(Test Cases)必須定義Test Fixture,在NUnitLite裡使用屬性[TestFixture]辨別該類為Test Fixture。具體的測試就是該類的方法(Methods)。NUnitLite支援SetUp和TearDown,SetUp在執行測試案例之前先執行,用于初始化和配置設定資源,可以通過屬性[SetUp]指定SetUp方法;TearDown在執行完測試案例後執行,用于釋放相應的資源,可以使用屬性[TearDown]指定TearDown方法。屬性[Test]用于定義需要執行的測試案例,Test Runner會執行Test Fixture下所有的[Test]方法。
下面為測試案例的編寫,也就是[Test]方法。

public void ExecuteNonQueryTest()
int i = sqlCe.ExecuteNonQuery("delete from t");
Assert.That(i, Is.GreaterThan(-1));
i = sqlCe.ExecuteNonQuery("insert into t (f1, f2) values (1, 'abc')");
i = sqlCe.ExecuteNonQuery("update t set f2 = 'xyz' where f1 = 1");
public void ExecuteReaderTest()
SqlCeDataReader reader = sqlCe.ExecuteReader("select * from t");
Assert.NotNull(reader);
Assert.True(!reader.IsClosed);
while (reader.Read())
{
Assert.That(Is.Equals(reader["f2"], "abc"));
}
reader.Close();
public void ExecuteDataSetTest()
DataSet ds = sqlCe.ExecuteDataSet("select * from t");
foreach (DataRow dr in ds.Tables[0].Rows)
Assert.That(dr["f2"], Is.EqualTo("xyz"));
[ExpectedException(typeof(ApplicationException))]
public void ThrowsException()
throw new ApplicationException("an application exception");

在NUnitLite中進行檢驗值還是使用Assert,但是不能使用NUnit下的AreEquels等判斷方法,需要使用Assert.That和Is類組合完成AreEquels等判斷函數的功能。同時NUnitLite還是支援異常的捕捉(ExpectedException)。
程式運作後會生成運作結果如下:

NUnitLite version 0.2.0
Copyright 2007, Charlie Poole
Runtime Environment -
OS Version: Microsoft Windows CE 5.0.0
.NET Version: 2.0.7045.0
4 Tests : 0 Errors, 1 Failures, 0 Not Run
Errors and Failures:
1) ExecuteReaderTest (TestNameSpace.SqlCeHelperTest.ExecuteReaderTest)
Expected: True
But was: False
at TestNameSpace.SqlCeHelperTest.ExecuteReaderTest()
at System.Reflection.RuntimeMethodInfo.InternalInvoke()
at System.Reflection.RuntimeMethodInfo.Invoke()
at System.Reflection.MethodBase.Invoke()
at NUnitLite.Reflect.InvokeMethod()
at NUnitLite.TestCase.InvokeMethod()
at NUnitLite.TestCase.RunTest()
at NUnitLite.TestCase.RunBare()
at NUnitLite.TestCase.Run()
at NUnitLite.TestSuite.Run()
at NUnitLite.Runner.TestRunner.Run()
at NUnitLite.Runner.TextUI.Run()
at NUnitLite.Runner.TextUI.Execute()
at TestNameSpace.TestForm.Main()

<a></a>