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

asserting Assert.ThrowsException and failing creates an exception where the message include the message and stacktrace in it #2761

Open
Meir017 opened this issue Apr 24, 2024 · 0 comments

Comments

@Meir017
Copy link

Meir017 commented Apr 24, 2024

Describe the bug

In the following method the exception fails and throws AssertFailedException.

The exception message

[TestMethod, ExpectedException(typeof(AssertFailedException))]
public async Task AssertThrowsExceptionAsync_Failure_OldAssertion()
{
    // arrange
    static Task ThrowExceptionAsync() => throw new InvalidOperationException();
    Func<Task> action = ThrowExceptionAsync;
    
    // old assertion:
    await Assert.ThrowsExceptionAsync<ArgumentException>(action);
}

Steps To Reproduce

using Assert.ThrowsException or Assert.ThrowsExceptionAsync and failing throws an AssertFailedException exception where the Message property contains "Exception Message: <the message>" and the "Stack Trace: at <stack-trace>"

Expected behavior

The exception's Message property should only include the fail message (like any other assertion method in mstest)

Actual behavior

Additional context

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

No branches or pull requests

1 participant