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:
AreEqual and AreNotEqual—These methods rely on the Object.Equals
method to determine object equality. There are various overloads for primitives, as well as reference types.
AreSame and AreNotSame—Tests 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.
Fail—Allows you to explicitly fail a test based on logic within the test method.
Inconclusive—Allows you to explicitly set the outcome of a test to inconclusive.
IsTrue and IsFalse—Verifies that a Boolean value is either true
or false
.
IsInstanceOfType and IsNotInstanceOfType—Verifies that an object instance does or does not inherit from a specified type.
IsNull and IsNotNull—Verifies 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.
3.137.217.41