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