Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Custom hook for assertion failure #3192

Open
filzrev opened this issue Feb 27, 2025 · 0 comments
Open

Feature Request: Custom hook for assertion failure #3192

filzrev opened this issue Feb 27, 2025 · 0 comments
Labels

Comments

@filzrev
Copy link

filzrev commented Feb 27, 2025

I want to gets actual/expected instance data when xUnit assertion failed.
And report custom diffs as test attachments.

Currently it need to add try-catch block capture these information.
So I want extensibility point to hook assertion failure event.

Expected Usage

public class ReportDiffOnFailedAttribute : BeforeAfterTestAttribute
{
    public override void Before(MethodInfo methodUnderTest, IXunitTest test)
    {
        // Add custom hook that is ivoked when assertion failed
        TestContext.Current.OnAssertionFailed = (string assertionName, object? actual, object? expected) =>
        {
            // Generate actual/expected diffs and add results to attachments.
        };
    }
}

Similar Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants