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