-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit2009
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit2009 |
Severity | Warning |
Enabled | True |
Category | Structure |
Code | SameActualExpectedValueAnalyzer |
The same value has been provided as both actual and 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.
#pragma warning disable NUnit2009 // Same value provided as actual and expected argument.
Code violating the rule here
#pragma warning restore NUnit2009 // Same value provided as actual and expected argument.
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2009 // Same value provided as actual and expected argument.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit2009:Same value provided as actual and expected argument.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0