docs/articles/nunit-analyzers/NUnit1007.md
| Topic | Value |
|---|---|
| Id | NUnit1007 |
| Severity | Error |
| Enabled | True |
| Category | Structure |
| Code | TestMethodUsageAnalyzer |
The method has non-void return type, but no result is expected in ExpectedResult.
To prevent tests that will fail at runtime due to improper construction.
[TestCase(1)]
public string NUnit1007SampleTest(int inputValue)
{
return "";
}
No ExpectedResult was defined, but the return type of the method in our sample is of type string, meaning it does
indeed return a result and we should use the ExpectedResult syntax in order to capture it.
Either modify the TestCase to add an ExpectedResult:
[TestCase(1, ExpectedResult = "")]
public string NUnit1007SampleTest(int inputValue)
{
return "";
}
Or modify the return type of the test method to be void:
[TestCase(1)]
public void NUnit1007SampleTest(int inputValue)
{
return Assert.That(inputValue, Is.EqualTo(1));
}
Configure the severity per project, for more info see MSDN.
# NUnit1007: The method has non-void return type, but no result is expected in ExpectedResult
dotnet_diagnostic.NUnit1007.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit1007 // The method has non-void return type, but no result is expected in ExpectedResult
Code violating the rule here
#pragma warning restore NUnit1007 // The method has non-void return type, but no result is expected in ExpectedResult
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1007 // The method has non-void return type, but no result is expected in ExpectedResult
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1007:The method has non-void return type, but no result is expected in ExpectedResult",
Justification = "Reason...")]