-
Notifications
You must be signed in to change notification settings - Fork 160
NUnit1006
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
| 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.
#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.[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1006:ExpectedResult must not be specified when the method returns void.",
Justification = "Reason...")]Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0