Permalink
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (38 sloc) 1.05 KB
title description category severity
xUnit2003
Do not use equality check to test for null value
Assertions
Warning

Cause

A violation of this rule occurs when Assert.Equal, AssertNotEqual, Assert.StrictEqual, or Assert.NotStrictEqual are used with null.

Reason for rule

Assert.Null and Assert.NotNull should be used when checking against null.

How to fix violations

To fix a violation of this rule, replace the offending asserts with Assert.Null or Assert.NotNull.

Examples

Violates

[Fact]
public void ExampleMethod()
{
    string result = GetSomeValue();

    Assert.NotEqual(null, result);
    Assert.Equal(null, result);
}

Does not violate

[Fact]
public void ExampleMethod()
{
    string result = GetSomeValue();

    Assert.NotNull(result);
    Assert.Null(result);
}

How to suppress violations

#pragma warning disable xUnit2003 // Do not use equality check to test for null value
#pragma warning restore xUnit2003 // Do not use equality check to test for null value