-
Notifications
You must be signed in to change notification settings - Fork 291
Open
Labels
Description
Describe the bug
When using a [DoesNotReturn] Assertion like Assert.Fail, MSTEST0058 is still triggered.
Version used
MSTest.Sdk 4.1
Steps To Reproduce
try
{
(await Assert.ThrowsExactlyAsync<UnauthorizedAccessException>(() => System.IO.File.ReadAllTextAsync(share.Combine("Test.txt"), ct)))
.Message.ShouldBe($@"Access to the path '{share.Combine("Test.txt")}' is denied.");
}
catch (AssertFailedException ex) when (ex.Message.Contains("no exception was thrown.", StringComparison.Ordinal))
{
#pragma warning disable MSTEST0058 // Avoid assertions in catch blocks
Assert.Inconclusive("We should not have access to this path. This suggests the share is still mounted and does not disconnect (until a system reboot).");
#pragma warning restore MSTEST0058
}
Expected behavior
no warning when catch always throws assertion exception.
Actual behavior
warning MSTEST0058: Do not use asserts in catch blocks because they may not fail the test if no exception is thrown (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0058)