Edit on GitHub

xUnit2006 Warning

Do not use invalid string equality check

Cause

A violation of this rule occurs when the generic overloads of Assert.Equal or Assert.StrictEqual are used with string.

Reason for rule

There is an optimized overload of both Assert.Equal and Assert.StrictEqual for string arguments.

How to fix violations

To fix a violation of this rule, remove the generic argument to use the string overload.

Examples

Violates

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

    Assert.Equal<string>("foo", result);
}

Does not violate

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

    Assert.Equal("foo", result);
}

How to suppress violations

#pragma warning disable xUnit2006 // Do not use invalid string equality check
#pragma warning restore xUnit2006 // Do not use invalid string equality check
Copyright © 2017 .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit.analyzers.