docs/articles/nunit-analyzers/NUnit1006.md
| Topic | Value |
|---|---|
| Id | NUnit1006 |
| Severity | Error |
| Enabled | True |
| Category | Structure |
| Code | TestMethodUsageAnalyzer |
ExpectedResult must not be specified when the method returns void. This will lead to an error at run-time.
To prevent tests that will fail at runtime due to improper construction.
[TestCase(1, ExpectedResult = "1")]
public void NUnit1006SampleTest(int inputValue)
{
return;
}
An ExpectedResult was defined, but the return type of the method in our sample is of type void, meaning it does not
return a result.
Either modify the TestCase to remove the ExpectedResult:
[TestCase(1)]
public void NUnit1006SampleTest(int inputValue)
{
Assert.That(inputValue, Is.EqualTo(1));
}
Or modify the return type of the test method:
[TestCase(1, ExpectedResult = "1")]
public string NUnit1006SampleTest(int inputValue)
{
return inputValue.ToString();
}
Configure the severity per project, for more info see MSDN.
# NUnit1006: ExpectedResult must not be specified when the method returns void
dotnet_diagnostic.NUnit1006.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit1006 // ExpectedResult must not be specified when the method returns void
Code violating the rule here
#pragma warning restore NUnit1006 // ExpectedResult must not be specified when the method returns void
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1006 // ExpectedResult must not be specified when the method returns void
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1006:ExpectedResult must not be specified when the method returns void",
Justification = "Reason...")]