-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit1005
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit1005 |
Severity | Error |
Enabled | True |
Category | Structure |
Code | TestMethodUsageAnalyzer |
The type of ExpectedResult must match the return type. This will lead to an error at run-time.
To prevent tests that will fail at runtime due to improper construction.
[TestCase(1, ExpectedResult = true)]
public int NUnit1005SampleTest(int inputValue)
{
return inputValue;
}
The sample above uses NUnit's ExpectedResult
syntax. It defines a result of true
(a bool
) but the return type of the method is int
.
Either modify the TestCase parameter:
[TestCase(1, ExpectedResult = 1)]
public int NUnit1005SampleTest(int inputValue)
{
return inputValue;
}
Or modify the return type and logic of the method:
[TestCase(1, ExpectedResult = true)]
public bool NUnit1005SampleTest(int inputValue)
{
return inputValue > 0;
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit1005 // The type of ExpectedResult must match the return type.
Code violating the rule here
#pragma warning restore NUnit1005 // The type of ExpectedResult must match the return type.
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1005 // The type of ExpectedResult must match the return type.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1005:The type of ExpectedResult must match the return type.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0