Search Results for

    Show / Hide Table of Contents

    True Constraint

    TrueConstraint tests that a value is true. Use this constraint when asserting boolean conditions or the result of boolean expressions.

    Usage

    Is.True
    Is.Not.True  // equivalent to Is.False
    

    Examples

    [Test]
    public void TrueConstraint_Examples()
    {
        Assert.That(2 + 2 == 4, Is.True);
        var isValid = true;
        Assert.That(isValid, Is.True);
        var list = new List<int> { 1, 2, 3 };
        Assert.That(list.Contains(2), Is.True);
    
        // With nullable booleans
        bool? hasValue = true;
        Assert.That(hasValue, Is.True);
    }
    

    Notes

    1. Is.Not.True is equivalent to Is.False for non-nullable booleans.
    2. For nullable booleans (bool?), Is.True only passes when the value is exactly true, not when it's null.

    See Also

    • False Constraint
    • 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