Edit on GitHub

xUnit2004 Warning

Do not use equality check to test for boolean conditions

Cause

A violation of this rule occurs when:

Reason for rule

It’s more readable to use Assert.True or Assert.False instead.

How to fix violations

For Equal and StrictEqual

For NotEqual and NotStrictEqual

How to suppress violations

#pragma warning disable xUnit2004 // AssertEqualShouldNotBeUsedForBoolLiteralCheck
#pragma warning restore xUnit2004 // AssertEqualShouldNotBeUsedForBoolLiteralCheck

Examples

Violates

Assert.Equal(true, 2 + 2 == 4);
Assert.Equal(false, 2 + 2 == 5);

Does not violate

Assert.True(2 + 2 == 4);
Assert.False(2 + 2 == 5);
Copyright © 2017 .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit.analyzers.