Assert.AreEqual(expected, actual[, string message])
//expected:期望值(通常是硬编码的);
//actual:被测试代码实际产生的值;
//message:一个可选消息,将会在发生错误时报告这个消息。
Assert.AreEqual(expected, actual, tolerance[, string message])
//tolerance:指定的误差,即只要精确到小数点后X位就足够了。
//例如:精确到小数点后4位
Assert.AreEqual(0.6667, 0.0/3.0, 0.0001);
Assert.IsNull(object[, string message])
//是null
Assert.IsNotNull(object[, string message])
//非null
Assert.AreSame(expected, actual[, string message])
//验证expected和actual两个参数是否引用一个相同的对象。
Assert.IsTrue(bool condition [, string message])
Assert.IsFalse(bool condition [, string message])
Assert.Fail([string message])
//使测试立即失败;这种断言通常被用于标记某个不应该被到达的分支,但实际中不常用。
using NUint.Framework;
[TestFixture]
public class TestSimple 

{
[Test]
public void TestMethod() 
{
Assert.AreEqual(2, 4/2);
}
}
1)需要NUint.Framework的命名空间,项目中需要引用NUint.dll;
2)每个包含测试的类都必须带TestFixture属性标记,且这个类必须是public的。
3)测试类包含的所有带Test属性标记的public方法都会被NUint自动执行。
8.NUint的分类Categories
用Category的概念提供了标记和运行一个个单独的测试和TestFixture的简单方法。
一个Category是自己定义的一个名字。可把不同的测试方法关联到一个或多个Category,然后运行测试的时候选择自己想要运行的Category。
如,实际中有些测试只需几秒就能完成,而有些则须长时间才能完成,为了避免每次都执行长时间的测试,可使用分类来标记它们,然后运行测试指定需要运行的Category。
[Test]
[Category("Short")]
public void ShortTest()

{
//do some tests.
}
[Test, Category("Long")] //两种属性的写法就可以
public void LondTest()

{
//do some tests.
}
[Category("Special", Explicit=true)]
[SetUp] //用于测试环境的建立
public void MySetup()
{
//do something.
}
[TearDown] //清除测试环境
public void MyTeardown()
{
//do something.
}
//如测试是否抛出ArgumentException
[Test, ExpectedException(typeof(ArgumentException))]
public void TestForException() 

{
Do.GetSomething(null);
//Shouldn's get to here;
}
[Test, Ignore("Not run this method")]
public void TestMethod()

{
//do something
}