Defines a set of assertions that enable a test to verify the expected behavior of the subject under test.

Namespace:  MbUnit.Framework
Assembly:  MbUnit (in MbUnit.dll) Version: 3.2.0.0 (3.2.570.0)

Syntax

C#
public abstract class Assert
Visual Basic (Declaration)
Public MustInherit Class Assert

Remarks

Each assertion is generally provided in at least 4 flavors distinguished by overloads:

  • A simple form that takes only the assertion parameters.
  • A simple form that accepts a custom message format string and arguments in addition to the assertion parameters.
  • A rich form that takes the assertion parameters and a custom comparer object.
  • A rich form that accepts a custom message format string and arguments in addition to the assertion parameters and a custom comparer object.

The value upon which the assertion is being evaluated is usually called the "actual value". Other parameters for the assertion are given names such as the "expected value", "unexpected value", or other terms as appropriate. In some cases where the role of a parameter is ambiguous, we may use designations such as "left" and "right" to distinguish the parameters.

The Assert class does not provide direct support for old-style collection types such as ICollection and IEnumerable. If you are using .Net 3.5 for your test projects, you may find the "Cast" function helpful.

Examples

CopyC#
ICollection myOldCollection = subjectUnderTest.DoSomething();
Assert.AreElementsEqual(new[] { "a", "b", "c" }, myOldCollection.Cast<string>());

Framework authors may choose to extend this class with additional assertions by creating a subclass. Alternately, new assertions can be defined in other classes.

When formatting values for inclusion in assertion failures, it is recommended to use the formatter provided by the Formatter property instead of directly calling ToString()()(). This enables custom formatting rules to decide how best to present values of particular types and yields a more consistent user experience. In particular the AddRawLabeledValue(String, Object) method and its siblings automatically format values in this manner.

Inheritance Hierarchy

System..::.Object
  MbUnit.Framework..::.Assert
    MbUnit.Framework..::.AssertEx

See Also