Search Results for

    Show / Hide Table of Contents

    Classic Model

    The classic Assert model uses a separate method to express each individual assertion of which it is capable.

    Here's a simple assert using the classic model:

    StringAssert.AreEqualIgnoringCase("Hello", myString);
    
    Note

    From version 4.5.0, using C# 14, you don't need to use the ClassicAssert class, nor the NUnit.Framework.Legacy namespace, but can use the former Assert class. This applies for many of the asserts, but a few still require the use of the ClassicAssert class. These will be fixed in upcoming releases. In the list below, and in the examples, the 4.5.0 syntax will be used. If you use an earlier 4.x version, replace Assert with ClassicAssert and include the NUnit.Framework.Legacy namespace.

    The ClassicAssert and NUnit.Framework.Legacy are still available in 4.5.0, so you don't need to change code that already use this.

    See classic extensions for a full table over all extension mappings.

    The Assert class provides the most common classic assertions in NUnit:

    • Assert.True
    • Assert.False
    • Assert.Null
    • Assert.NotNull
    • Assert.Zero
    • Assert.NotZero
    • Assert.IsNaN
    • Assert.IsEmpty
    • Assert.IsNotEmpty
    • Assert.AreEqual
    • Assert.AreNotEqual
    • Assert.AreSame
    • Assert.AreNotSame
    • Assert.Contains
    • Assert.Greater
    • Assert.GreaterOrEqual
    • Assert.Less
    • Assert.LessOrEqual
    • Assert.Positive
    • Assert.Negative
    • Assert.IsInstanceOf
    • Assert.IsNotInstanceOf
    • Assert.IsAssignableFrom
    • Assert.IsNotAssignableFrom
    • Assert.Throws
    • Assert.ThrowsAsync
    • Assert.DoesNotThrow
    • Assert.DoesNotThrowAsync
    • Assert.Catch
    • Assert.CatchAsync

    Additional assertions are provided by the following classes, which are in the NUnit.Framework.Legacy namespace:

    • String Assert
    • Collection Assert
    • File Assert
    • Directory Assert

    See Also

    • Constraint Model

    Notes

    • The exception-family of classic asserts have not been moved to the legacy namespace.
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0