diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.Core.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.Core.cs index 27c9629f21..a81c307541 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.Core.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.Core.cs @@ -180,9 +180,10 @@ private static void ReportThrowsFailed( string expectedTypeLabel = isStrictType ? expectedTypeFullName : $"{expectedTypeFullName} (or derived)"; + // The "actual exception:" line is already prefixed with the exception type name, so we don't emit a + // separate "actual type:" line to avoid duplicating that information. EvidenceBlock evidence = EvidenceBlock.Create() .AddLine("expected type:", expectedTypeLabel) - .AddLine("actual type:", actualTypeFullName) .AddLine("actual exception:", $"{actualTypeFullName}: {actualException.Message}"); message = new StructuredAssertionMessage(summary) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index a219c229e9..7b3c4a0749 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -75,7 +75,6 @@ public void ThrowsAsync_WhenExceptionIsNotExpectedType_ShouldThrow() Assertion failed. Expected exception of type ArgumentException (or derived) but caught Exception. expected type: System.ArgumentException (or derived) - actual type: System.Exception actual exception: System.Exception: Exception of type 'System.Exception' was thrown. Assert.ThrowsAsync(() => throw new Exception()) @@ -93,7 +92,6 @@ public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThro Assertion failed. Expected exception of exact type ArgumentException but caught ArgumentNullException. expected type: System.ArgumentException - actual type: System.ArgumentNullException actual exception: System.ArgumentNullException: Value cannot be null. Assert.ThrowsExactlyAsync(() => throw new ArgumentNullException()) @@ -152,7 +150,6 @@ Assertion failed. Expected exception of type ArgumentNullException (or derived) message constructed via builder. expected type: System.ArgumentNullException (or derived) - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'MyParamNameHere') Assert.Throws(() => throw new ArgumentOutOfRangeException("MyParamNameHere")) @@ -162,7 +159,6 @@ Assertion failed. Expected exception of type ArgumentNullException (or derived) message constructed via builder. expected type: System.ArgumentNullException (or derived) - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: MyParamNameHere @@ -226,7 +222,6 @@ Assertion failed. Expected exception of exact type ArgumentNullException but cau message constructed via builder. expected type: System.ArgumentNullException - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'MyParamNameHere') Assert.ThrowsExactly(() => throw new ArgumentOutOfRangeException("MyParamNameHere")) @@ -236,7 +231,6 @@ Assertion failed. Expected exception of exact type ArgumentNullException but cau message constructed via builder. expected type: System.ArgumentNullException - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: MyParamNameHere @@ -300,7 +294,6 @@ Assertion failed. Expected exception of type ArgumentNullException (or derived) message constructed via builder. expected type: System.ArgumentNullException (or derived) - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'MyParamNameHere') Assert.ThrowsAsync(() => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere"))) @@ -310,7 +303,6 @@ Assertion failed. Expected exception of type ArgumentNullException (or derived) message constructed via builder. expected type: System.ArgumentNullException (or derived) - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: MyParamNameHere @@ -374,7 +366,6 @@ Assertion failed. Expected exception of exact type ArgumentNullException but cau message constructed via builder. expected type: System.ArgumentNullException - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'MyParamNameHere') Assert.ThrowsExactlyAsync(() => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere"))) @@ -384,7 +375,6 @@ Assertion failed. Expected exception of exact type ArgumentNullException but cau message constructed via builder. expected type: System.ArgumentNullException - actual type: System.ArgumentOutOfRangeException actual exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: MyParamNameHere @@ -436,7 +426,6 @@ public void Throws_WhenExceptionMessageContainsNewline_ContinuationLinesAreInden Assertion failed. Expected exception of type ArgumentException (or derived) but caught InvalidOperationException. expected type: System.ArgumentException (or derived) - actual type: System.InvalidOperationException actual exception: System.InvalidOperationException: line1 line2 @@ -461,7 +450,6 @@ static void Action() => Assert.Throws(() => Assertion failed. Expected exception of type ArgumentException (or derived) but caught InvalidOperationException. expected type: System.ArgumentException (or derived) - actual type: System.InvalidOperationException actual exception: System.InvalidOperationException: oops Assert.Throws() @@ -481,7 +469,6 @@ public void Throws_WhenExpectedTypeIsGeneric_RendersFriendlyTypeName() Assertion failed. Expected exception of type ThrowsTestGenericException (or derived) but caught InvalidOperationException. expected type: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ThrowsTestGenericException (or derived) - actual type: System.InvalidOperationException actual exception: System.InvalidOperationException: oops Assert.Throws>(() => throw new InvalidOperationException("oops"))