Do not use equality check to test for boolean conditions
A violation of this rule occurs when:
Assert.Equal
, Assert.NotEqual
, Assert.StrictEqual
, or Assert.NotStrictEqual
is usedtrue
or false
literalIt’s more readable to use Assert.True
or Assert.False
instead.
For Equal
and StrictEqual
Assert.Equal(true, b)
=> Assert.True(b)
Assert.StrictEqual(true, b)
=> Assert.True(b)
Assert.Equal(false, b)
=> Assert.False(b)
Assert.StrictEqual(false, b)
=> Assert.False(b)
For NotEqual
and NotStrictEqual
Assert.NotEqual(true, b)
=> Assert.False(b)
Assert.NotStrictEqual(true, b)
=> Assert.False(b)
Assert.NotEqual(false, b)
=> Assert.True(b)
Assert.NotStrictEqual(false, b)
=> Assert.True(b)
using Xunit;
public class xUnit2004
{
[Fact]
public void TestMethod()
{
var result = 2 + 2;
Assert.Equal(true, result > 3);
}
}
using Xunit;
public class xUnit2004
{
[Fact]
public void TestMethod()
{
var result = 2 + 2;
Assert.True(result > 3);
}
}