Skip to content

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

Closed
@Meir017

Description

@Meir017

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions