Edit on GitHub

xUnit2000 Warning

Expected value should be first

Cause

A violation of this rule occurs when the first argument to Assert.Equal, AssertNotEqual, Assert.StrictEqual, or Assert.NotStrictEqual is not the expected value.

Reason for rule

The expected value in equality assertions should always be the first 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

[Fact]
public void AdditionExample()
{
    var result = 2 + 3;

    Assert.Equal(result, 5);
}

Does not violate

[Fact]
public void AdditionExample()
{
    var result = 2 + 3;

    Assert.Equal(5, result);
}

How to suppress violations

#pragma warning disable xUnit2000 // Expected value should be first
#pragma warning restore xUnit2000 // Expected value should be first
Copyright © 2017 .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit.analyzers.