-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit2013
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit2013 |
Severity | Info |
Enabled | True |
Category | Assertion |
Code | StringConstraintUsageAnalyzer |
Using constraints instead of boolean methods will lead to better assertion messages in case of failure.
Using Does.EndWith
(or Does.Not.EndWith
) constraint will lead to better assertion messages in case of failure,
so this analyzer marks all usages of string EndsWith
method where it is possible to replace
with Does.EndWith
constraint.
[Test]
public void Test()
{
string actual = "...";
string expected = "...";
Assert.True(actual.EndsWith(expected));
}
The analyzer comes with a code fix that will replace Assert.True(actual.EndsWith(expected))
with
Assert.That(actual, Does.EndWith(expected))
. So the code block above will be changed into
[Test]
public void Test()
{
string actual = "...";
string expected = "...";
Assert.That(actual, Does.EndWith(expected));
}
<!-- start generated config severity -->
## Configure severity
### Via ruleset file.
Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx).
### Via #pragma directive.
```C#
#pragma warning disable NUnit2013 // Use EndsWithConstraint.
Code violating the rule here
#pragma warning restore NUnit2013 // Use EndsWithConstraint.
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2013 // Use EndsWithConstraint.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2013:Use EndsWithConstraint.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0