Verifying Conditions with Assertions

,

Assertions are the cornerstone of UTF. The Assert class has a multitude of test related method overloads that allow you to ensure the validity of your app’s state and behavior. The following is the core set of assertions used by most test classes:

Image AreEqual and AreNotEqualThese methods rely on the Object.Equals method to determine object equality. There are various overloads for primitives, as well as reference types.

Image AreSame and AreNotSameTests for whether two variables refer to the same object instance. These methods rely on the Object.ReferenceEquals method. There are various overloads for primitives, as well as reference types.

Image FailAllows you to explicitly fail a test based on logic within the test method.

Image InconclusiveAllows you to explicitly set the outcome of a test to inconclusive.

Image IsTrue and IsFalseVerifies that a Boolean value is either true or false.

Image IsInstanceOfType and IsNotInstanceOfTypeVerifies that an object instance does or does not inherit from a specified type.

Image IsNull and IsNotNullVerifies that an object is, or is not, null.

If an Assert method fails, it raises a UnitTestAssertException, which is handled by the UTF infrastructure and is reported back to you as a test failure.

To complement the set methods provided by the Assert classes, there exists a CollectionAssert class, with methods particular to collections, and a StringAssert class, which provides assertions based on regular expressions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.41