Skip to content

Add Assert.Scope() for soft assertions#7355

Draft
Evangelink wants to merge 2 commits intomainfrom
dev/amauryleve/soft-assertion
Draft

Add Assert.Scope() for soft assertions#7355
Evangelink wants to merge 2 commits intomainfrom
dev/amauryleve/soft-assertion

Conversation

@Evangelink
Copy link
Member

Fixes #571

@@ -37,8 +37,19 @@ private Assert()
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowAssertFailed(string assertionName, string? message)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this PR and #2033, I think it'd be good to expose a "ReportFailure" method that could be used by devs extending MSTest assertions so they would benefits from the various features (launch debugger, soft assertions....). I am not doing it here because we can decide not to go with it for now.

if (scope is not null)
{
scope.AddError(assertionFailedException);
#pragma warning disable CS8763 // A method marked [DoesNotReturn] should not return.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Youssef1313 I don't know what we prefer but it feels better for me to say we continue to help compiler with the default behavior and we know we may have some FPs when code is used under assertion scope. It would otherwise be a breaking change for many people if we had to update all assertion APIs to no longer respect some of these DoesNotReturn compilation indication.

/// // AssertFailedException is thrown here with all collected failures.
/// </code>
/// </example>
public static IDisposable Scope() => new AssertScope();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public API is quite limited, do we want to make it experimental still?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there any way to soft assert in MSTEST just like verify assert in TESTNG

1 participant