@H_404_0@
@H_404_0@
使用Assert(断言)进行比较,是一个类,包括的静态方法有:
1. Assert.AreEqual(object expected,object actual[,string message])
verifies that two objects are equal
if they are not equal,an NUnit.Framwork.AssertionException is thrown
参数说明:
expected:期望值(通常是硬编码的)
actual:被测试代码实际产生的值、
message:一个可选消息,将会在发生错误时报告这个消息
@H_404_0@
@H_404_0@
比较浮点数(float或double)时,要指定一个额外的误差参数
@H_404_0@
2. Assert.AreEqual(object expected,object actual,float tolerance[,string message])
参数说明:
tolerance:指定的误差,即精确到小数点后X位
例如:精确到小数点后4位,Assert.AreEqual(0.6667,2.0/3,0.0001);
@H_404_0@
@H_404_0@
3. Assert.AreNotEqual(object expected,object actual)
asserts that two objects are not equal
4. Assert.AreSame(object expected,string message])
asserts that two objects refer to the same object
验证expected和actual两个参数是否引用一个相同的对象
5. Assert.AreNotSame(object expected,string message])
asserts that two objects do refer to the same object
6. Assert.IsNull(object[,string message])
7. Assert.IsNotNull(object[,string message])
8. Assert.IsTrue(bool condition [,string message])
9. Assert.IsFalse(bool condition [,string message])
10. Assert.Fail([string message])
使测试立即失败
该断言被用于标记某个不应被到达的分支,实际不常用
@H_404_0@
@H_404_0@
其中很多方法的重载方法有很多种