-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit1007
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit1007 |
Severity | Error |
Enabled | True |
Category | Structure |
Code | TestMethodUsageAnalyzer |
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.
#pragma warning disable NUnit1007 // Method has non-void return type, but no result is expected in ExpectedResult.
Code violating the rule here
#pragma warning restore NUnit1007 // 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 // Method has non-void return type, but no result is expected in ExpectedResult.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1007:Method has non-void return type, but no result is expected in ExpectedResult.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0