Topic | Value |
---|---|
Id | NUnit2045 |
Severity | Info |
Enabled | True |
Category | Assertion |
Code | UseAssertMultipleAnalyzer |
Hosting Asserts inside an Assert.Multiple allows detecting more than one failure.
When independent Assert
statements are called from an Assert.Multiple
they all will run.
This allows detecting more than one failure in a single test run.
Without the Assert.Multiple
the below code will stop executing after the first failure and the second
violation won't be detected until the next run when the first one has been finished.
Assert.That(instance.Property1, Is.EqualTo(expectedProperty1Value));
Assert.That(instance.Property2, Is.EqualTo(expectedProperty2Value));
Add an Assert.Multiple
and call all independent Assert
statements from the lambda parameter.
Assert.Multiple(() =>
{
Assert.That(instance.Property1, Is.EqualTo(expectedProperty1Value));
Assert.That(instance.Property2, Is.EqualTo(expectedProperty2Value));
});
Configure the severity per project, for more info see MSDN.
# NUnit2045: Use Assert.Multiple
dotnet_diagnostic.NUnit2045.severity = chosenSeverity
where chosenSeverity
can be one of none
, silent
, suggestion
, warning
, or error
.
#pragma warning disable NUnit2045 // Use Assert.Multiple
Code violating the rule here
#pragma warning restore NUnit2045 // Use Assert.Multiple
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2045 // Use Assert.Multiple
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2045:Use Assert.Multiple",
Justification = "Reason...")]