Edit on GitHub

xUnit2000   v2 v3   Warning

Constants and literals should be the expected argument

Cause

A violation of this rule occurs when the expected argument to Assert.Equal, AssertNotEqual, Assert.StrictEqual, or Assert.NotStrictEqual is not the expected value (such as a constant or literal).

Reason for rule

The expected value in equality assertions should always be the expected argument. This will ensure that generated messages explaining the test failure will correctly match the situation.

How to fix violations

To fix a violation of this rule, swap the arguments in the assertion, so that the expected value is the first.

Examples

Violates

using Xunit;

public class xUnit2000
{
    [Fact]
    public void TestMethod()
    {
        var result = 2 + 3;

        Assert.Equal(result, 5);
    }
}

Does not violate

using Xunit;

public class xUnit2000
{
    [Fact]
    public void TestMethod()
    {
        var result = 2 + 3;

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