-
Notifications
You must be signed in to change notification settings - Fork 157
NUnit2015
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit2015 |
Severity | Warning |
Enabled | True |
Category | Assertion |
Code | ClassicModelAssertUsageAnalyzer |
Consider using the constraint model, Assert.That(expr2, Is.SameAs(expr1)), instead of the classic model, Assert.AreSame(expr1, expr2).
The assert Assert.AreSame
from the classic Assert model makes it easy to confuse the expected
and the actual
argument,
so this analyzer marks usages of Assert.AreSame
.
[Test]
public void Test()
{
Assert.AreSame(expected, actual);
}
The analyzer comes with a code fix that will replace Assert.AreSame(expected, actual)
with
Assert.That(actual, Is.SameAs(expected))
. So the code block above will be changed into.
[Test]
public void Test()
{
Assert.That(actual, Is.SameAs(expected));
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit2015 // Consider using Assert.That(expr2, Is.SameAs(expr1)) instead of Assert.AreSame(expr1, expr2).
Code violating the rule here
#pragma warning restore NUnit2015 // Consider using Assert.That(expr2, Is.SameAs(expr1)) instead of Assert.AreSame(expr1, expr2).
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2015 // Consider using Assert.That(expr2, Is.SameAs(expr1)) instead of Assert.AreSame(expr1, expr2).
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2015:Consider using Assert.That(expr2, Is.SameAs(expr1)) instead of Assert.AreSame(expr1, expr2).",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0