-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit1014
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit1014 |
Severity | Error |
Enabled | True |
Category | Structure |
Code | TestMethodUsageAnalyzer |
Async test method must have Task return type when a result is expected
To prevent tests that will fail at runtime due to improper construction.
[TestCase(1, ExpectedResult = true)]
public async Task Nunit1014SampleTest(int numberValue)
{
return;
}
The NUnit ExpectedResult
syntax is used, so this method needs to return a type that matches the type of expected result you're looking for.
Remove the ExpectedResult
syntax:
[TestCase(1)]
public async Task Nunit1014SampleTest(int numberValue)
{
Assert.Pass();
}
Or, update the return task type to be what you're looking for, e.g. Task<bool>
below:
[TestCase(1, ExpectedResult = true)]
public async Task<bool> Nunit1014SampleTest(int numberValue)
{
return Task.FromResult(true);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit1014 // Async test method must have Task<T> return type when a result is expected
Code violating the rule here
#pragma warning restore NUnit1014 // Async test method must have Task<T> return type when a result is expected
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1014 // Async test method must have Task<T> return type when a result is expected
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1014:Async test method must have Task<T> return type when a result is expected",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0