Skip to content

NUnit2023

Mikkel Nylander Bundgaard edited this page Apr 25, 2020 · 2 revisions

NUnit2023

Invalid NullConstraint usage.

Topic Value
Id NUnit2023
Severity Warning
Enabled True
Category Assertion
Code NullConstraintUsageAnalyzer

Description

NullConstraint is allowed only for reference types or nullable value types.

Motivation

Non-nullable value types cannot have null value, therefore Is.Null assertions will always fail (or will always pass for Is.Not.Null).

How to fix violations

Use suitable constraint.

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable NUnit2023 // Invalid NullConstraint usage.
Code violating the rule here
#pragma warning restore NUnit2023 // Invalid NullConstraint usage.

Or put this at the top of the file to disable all instances.

#pragma warning disable NUnit2023 // Invalid NullConstraint usage.

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion", 
    "NUnit2023:Invalid NullConstraint usage.",
    Justification = "Reason...")]
Clone this wiki locally