Legacy Documentation. View NUnit 3 Documentation

Assertions

Assertions are central to unit testing in any of the xUnit frameworks, and NUnit is no exception. NUnit provides a rich set of assertions as static methods of the Assert class.

If an assertion fails, the method call does not return and an error is reported. If a test contains multiple assertions, any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test.

Each method may be called without a message, with a simple text message or with a message and arguments. In the last case the message is formatted using the provided text and arguments.

The Assert class provides the most commonly used assertions. It provides For convenience of presentation, we group Assert methods as follows:

Additional assertions on strings are provided by the StringAssert class.