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 Assert.Equal for string arguments.

How to fix violations

To fix a violation of this rule, use the non-generic version of Assert.Equal with the string overload.

Examples

Violates

using Xunit;

public class xUnit2006
{
    [Fact]
    public void TestMethod()
    {
        var result = "foo";

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

Does not violate

using Xunit;

public class xUnit2006
{
    [Fact]
    public void TestMethod()
    {
        var result = "foo";

        Assert.Equal("foo", result);
    }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.