Skip to content

Feature Request: Custom hook for assertion failure #3192

@filzrev

Description

@filzrev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureA request for a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions