Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
| Property | Value |
|---|---|
| Rule ID | MSTEST0017 |
| Title | Assertion arguments should be passed in the correct order |
| Category | Usage |
| Fix is breaking or non-breaking | Non-breaking |
| Enabled by default | Yes |
| Default severity | Warning starting with 4.0.0, Info before |
| Introduced in version | 3.4.0 |
| Is there a code fix | Yes |
Cause
This rule raises an issue when calls to Assert.AreEqual, Assert.AreNotEqual, Assert.AreSame or Assert.AreNotSame are following one or multiple of the patterns below:
actualargument is a constant or literal valueactualargument variable starts withexpected,_expectedorExpectedexpectedornotExpectedargument variable starts withactualactualis not a local variable
Rule description
MSTest Assert.AreEqual, Assert.AreNotEqual, Assert.AreSame and Assert.AreNotSame expect the first argument to be the expected/unexpected value and the second argument to be the actual value.
Having the expected value and the actual value in the wrong order will not alter the outcome of the test (succeeds/fails when it should), but the assertion failure will contain misleading information.
How to fix violations
Ensure that that actual and expected/notExpected arguments are passed in the correct order.
When to suppress warnings
Do not suppress a warning from this rule as it would result to misleading output.
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable MSTEST0017
// The code that's violating the rule is on this line.
#pragma warning restore MSTEST0017
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.MSTEST0017.severity = none
For more information, see How to suppress code analysis warnings.