TUnit
TUnit copied to clipboard
Unnecessary and prohibiting error about `await using` on `Assert.Multiple()`
I'm using the version 0.1.790, which only contains the single Assert.Multiple() overload that can be used as a scope without writing all the assertion logic inside a lambda expression passed into the multiple assertion scope.
There is an analyzer that reports the following error:
- TUnitAssertions0004 - Assert.Multiple needs an
await usingbefore it.
Which I find unnecessary. If you don't include the await keyword, the C# compiler itself will report an error about applying a simple using on an IAsyncDisposable, hinting using await using.
Example screenshot:
Workaround
To use this you need to suppress the error by doing:
#pragma warning disable TUnitAssertions0004 // Assert.Multiple needs an `await using` before it
VS provides a quick fix for that by suppressing and then restoring the error, although I would recommend completely disabling it throughout the entire file, or in the .editorconfig entirely.
Thanks - I'll look into this. Current workaround (apart from the pragma disable) is using a scope for the using:
await using (Assert.Multiple())
{
...
}
Imo it's best to completely remove this error, for the reason I explained above. I prefer typing the extra var _ = to allow the inline syntax, and avoid nesting all my assertions within the scope, since most of my testing logic is very small and linear.
I'll just make the analyzer accept both versions. I won't remove it because the dispose call is what performs the assertions, so if there's no analyzer to remind people to dispose then their assertions wouldn't run
Oh I completely missed the point of this diagnostic, thanks for the explanation
@Rekkonnect fixed in 0.1.797