testfx icon indicating copy to clipboard operation
testfx copied to clipboard

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

Open Meir017 opened this issue 1 year ago • 0 comments

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

Meir017 avatar Apr 24 '24 15:04 Meir017