Edit on GitHub

xUnit2022 Info

Boolean assertions should not be negated

Cause

This rule is triggered when you call a boolean assertion with a negated expression.

Reason for rule

The message that results from a negated expression is often less clear than the one that would result from a positive expression.

How to fix violations

To fix a violation of this rule, remove the negation and invert the assertion.

Examples

Violates

using Xunit;

public class TestClass
{
    [Fact]
    public void TestMethod()
    {
        Assert.True(!condition);
    }
}

Does not violate

using Xunit;

public class TestClass
{
    [Fact]
    public void TestMethod()
    {
        Assert.False(condition);
    }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.