Code inspection: NUnit. Async test method must return Task or Task<T>
Async test methods in NUnit 3.x must return either Task if no value is returned, or Task<T> if a value of type T is returned. Below are two situations where async tests will not be working correctly.
[Test] // Warning: Async test method is void
public async void Test1()
{
// do something
await Task.CompletedTask;
}
[Test] // Warning: NUnit 3.10 does not support ValueTask
public async ValueTask<int> Test2()
{
// do something
return await Task.FromResult(100);
}
In both situations you need to rewrite test methods so that they return either Task or Task<T>.
11 February 2024