Search Results for

    Show / Hide Table of Contents

    Assert.True

    Assert.True and Assert.IsTrue test that the specified condition is true. The two forms are provided for compatibility with past versions of NUnit and NUnitLite.

    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.

    Assert.True(bool condition);
    Assert.True(bool condition, string message, params object[] params);
    
    Assert.IsTrue(bool condition);
    Assert.IsTrue(bool condition, string message, params object[] params);
    

    You can also use Assert.That with a Boolean argument to achieve the same result.

    [Test]
    public void True_Examples()
    {
        Assert.True(2 + 2 == 4);
        Assert.IsTrue(true);
        Assert.True("Hello".StartsWith("H"));
        
    }
    

    See Also

    • Condition Constraints
    • 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