Unit Testing Conventions
Suppress Async Warning Project-Wide
Since we have several calls to base classes for diagnostics and such that are async, it's a good idea to standardize on all Test methods be async.
The problem is that not every test method contains an awaited call. so, we get compiler warnings for them.
NOTE: This can be added to legacy csproj files, as well (non SDK-based).
To do this, you have to open the csproj file in a text editor, and paste the lines into the top propertygroup block.
To suppress these warnings, add this to the PropertyGroup of the csproj of your Test projects:
<!-- NoWarn below suppresses CS1998 project-wide -->
<!-- This suppresses the IDE warning that the async method lack await. -->
<!-- We default all test methods to async, so the timing and dependency calls are the consistent. -->
<NoWarn>$(NoWarn);CS1998</NoWarn>
The csproj would look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<!-- NoWarn below suppresses CS1998 project-wide -->
<!-- This suppresses the IDE warning that the async method lack await. -->
<!-- We default all test methods to async, so the timing and dependency calls are the consistent. -->
<NoWarn>$(NoWarn);CS1998</NoWarn>
</PropertyGroup>
...
</Project>
No Comments