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