Assert class提供了一系列的static methods,让你可以用来验证主要程序的结果与预期的是否一样。

             常用的assert断言有:

            1. Assert.AreEqual(object expected,object actual[string message]):验证两个对象是否相等,如Assert.AreEqual(2,1+1);

            2. Assert.AreSame(object expected,object actual[string message]):验证两个引用是否指向同一对象,如

             object expected=new object(); 

             object actual =expected;

             Assert.AreSame(expected,actual);

             3.Assert.IsFalse(bool):验证bool值是否为false,如Assert.IsFalse(false);

             4.Assert.IsTrue(bool):验证bool值是否为true,如Assert.IsTrue(true);

             5.Assert.IsNotNull(object):验证对象是否不为null,如Assert.IsNotNull(new object());

             6.Assert.IsNull(object):验证对象是否为null,如Assert.IsNull(null);

posted on 2008-04-23 21:07  AFH  阅读(268)  评论(0编辑  收藏  举报