Skip to content

Openness for Caller Argument Expression in Assert failure messages #1154

@johnthcall

Description

@johnthcall

Description

With .Net 6 Caller Argument Expression was added, this could be used in testfx to provide the expression which failed the check. Doing this could provider consumers more out of the box detail about what caused the assert to fail without having to manually provide messages.

Sample Code change

#if !NET6_0_OR_GREATER
        public static void IsNull(object value)
        {
            IsNull(value, string.Empty, null);
        }
#endif

        public static void IsNull(
            object value,
#if !NET6_0_OR_GREATER
            string message)
#else
            [CallerArgumentExpression("value")]string message = "")
#endif
        {
            IsNull(value, message, null);
        }

Work required

  • Add .Net 6 as a built/packaged runtime
  • Modify Assert code to make the flows without a message removed in .Net 6 so that code like Assert.IsNull(myParam) execute passing myParam as the message.

Change in behavior

Currently a failing call to Assert.IsNull without a message will just return Assert.IsNull failed. This would change to Assert.IsNull failed. myParam which could be considered a breaking change and a result a no-go.

AB#1588958

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions