docs/articles/nunit-analyzers/NUnit2009.md
| Topic | Value |
|---|---|
| Id | NUnit2009 |
| Severity | Warning |
| Enabled | True |
| Category | Assertion |
| Code | SameActualExpectedValueAnalyzer |
The same value has been provided as both the actual and the expected argument. This indicates a coding error.
To bring developers' attention to a situation in which their code may not be operating as expected and their test may not be testing what they expect.
[Test]
public void NUnit2009SampleTest()
{
var x = 1;
Assert.That(x, Is.EqualTo(x));
}
In the above example, the test will always be correct, because we're comparing the same value. That is to say, we're not actually testing anything.
Ensure the expected and actual values come from different places.
[Test]
public void NUnit2009SampleTest()
{
var x = 1;
Assert.That(x, Is.EqualTo(1));
}
Configure the severity per project, for more info see MSDN.
# NUnit2009: The same value has been provided as both the actual and the expected argument
dotnet_diagnostic.NUnit2009.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Code violating the rule here
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2009:The same value has been provided as both the actual and the expected argument",
Justification = "Reason...")]