Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;
using System.Threading.Tasks;

using AwesomeAssertions;
Expand Down Expand Up @@ -146,10 +147,8 @@ public async Task RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertion
TestFailedException exception = (await new Func<Task>(() => _testAssemblyInfo.RunAssemblyInitializeAsync(_testContext)).Should().ThrowAsync<TestFailedException>()).Which;
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure. Aborting test execution.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.Should().Contain(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailure>");
#endif
"Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.DummyTestClass.AssemblyInitializeMethod");
exception.InnerException.Should().BeOfType<AssertFailedException>();
}

Expand All @@ -163,10 +162,8 @@ public async Task RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconcl
TestFailedException exception = (await new Func<Task>(() => _testAssemblyInfo.RunAssemblyInitializeAsync(_testContext)).Should().ThrowAsync<TestFailedException>()).Which;
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Inconclusive);
exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive. Aborting test execution.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.Should().Contain(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>");
#endif
"Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.DummyTestClass.AssemblyInitializeMethod");
exception.InnerException.Should().BeOfType<AssertInconclusiveException>();
}

Expand All @@ -179,10 +176,8 @@ public async Task RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAsse

exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.ArgumentException: Some actualErrorMessage message. Aborting test execution.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal).Should().BeTrue();
#endif
exception.StackTraceInformation!.ErrorStackTrace.Should().Contain(
"Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.DummyTestClass.AssemblyInitializeMethod");
exception.InnerException.Should().BeOfType<ArgumentException>();
exception.InnerException.InnerException.Should().BeOfType<InvalidOperationException>();
}
Expand All @@ -200,10 +195,8 @@ public async Task RunAssemblyInitializeShouldThrowTheInnerMostExceptionWhenThere

exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.InvalidOperationException: I fail.. Aborting test execution.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.FailingStaticHelper..cctor()", StringComparison.Ordinal).Should().BeTrue();
#endif
exception.InnerException.Should().BeOfType<InvalidOperationException>();
}

Expand Down Expand Up @@ -315,8 +308,16 @@ public class DummyTestClass

public TestContext TestContext { get; set; } = null!;

// On .NET Framework, the JIT aggressively inlines small methods in Release mode,
// which removes stack frames. NoInlining ensures the method appears in stack traces.
#if NETFRAMEWORK
[MethodImpl(MethodImplOptions.NoInlining)]
#endif
public static void AssemblyInitializeMethod(TestContext testContext) => AssemblyInitializeMethodBody.Invoke(testContext);

#if NETFRAMEWORK
[MethodImpl(MethodImplOptions.NoInlining)]
#endif
public static void AssemblyCleanupMethod() => AssemblyCleanupMethodBody.Invoke();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;

using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
Expand Down Expand Up @@ -335,10 +337,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMeth
exception.Should().NotBeNull();
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.InitBaseClassMethod threw exception. System.ArgumentException: Some exception message.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMethodWithNonAssertExceptions>", StringComparison.Ordinal).Should().BeTrue();
#endif
exception.InnerException.Should().BeOfType<ArgumentException>();
exception.InnerException.InnerException.Should().BeOfType<InvalidOperationException>();
}
Expand All @@ -355,10 +355,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure()
exception.Should().NotBeNull();
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.Contains(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal).Should().BeTrue();
#endif
"Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.DummyTestClass.ClassInitializeMethod", StringComparison.Ordinal).Should().BeTrue();
exception.InnerException.Should().BeOfType<AssertFailedException>();
}

Expand All @@ -374,10 +372,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAs
exception.Should().NotBeNull();
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Inconclusive);
exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.Contains(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>", StringComparison.Ordinal).Should().BeTrue();
#endif
"Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.DummyTestClass.ClassInitializeMethod", StringComparison.Ordinal).Should().BeTrue();
exception.InnerException.Should().BeOfType<AssertInconclusiveException>();
}

Expand All @@ -391,10 +387,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExcepti
exception.Should().NotBeNull();
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. System.ArgumentException: Argument exception.");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal).Should().BeTrue();
#endif
}

public void RunClassInitializeShouldThrowForAlreadyExecutedTestClassInitWithException()
Expand Down Expand Up @@ -431,10 +425,8 @@ public void RunClassInitializeShouldThrowTheInnerMostExceptionWhenThereAreMultip
exception.Should().NotBeNull();
exception.Outcome.Should().Be(UTF.UnitTestOutcome.Failed);
exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. System.InvalidOperationException: I fail..");
#if DEBUG
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.FailingStaticHelper..cctor()", StringComparison.Ordinal).Should().BeTrue();
#endif
exception.InnerException.Should().BeOfType<InvalidOperationException>();
}

Expand Down Expand Up @@ -494,11 +486,9 @@ public async Task RunClassCleanupShouldReturnAssertFailureExceptionDetails()
classCleanupException.Should().NotBeNull();
classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal).Should().BeTrue();
classCleanupException.Message.Contains("Error Message: Assert.Fail failed. Test Failure.").Should().BeTrue();
#if DEBUG
classCleanupException.Message.Should().Contain(
$"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertFailureExceptionDetails)}>",
$"{typeof(TestClassInfoTests).FullName}.DummyTestClass.ClassCleanupMethod",
$"Value: {classCleanupException.Message}");
#endif
}

public async Task RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails()
Expand All @@ -517,11 +507,9 @@ public async Task RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails(
classCleanupException.Should().NotBeNull();
classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal).Should().BeTrue();
classCleanupException.Message.Contains("Error Message: Assert.Inconclusive failed. Test Inconclusive.").Should().BeTrue();
#if DEBUG
classCleanupException.Message.Should().Contain(
$"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails)}>",
$"{typeof(TestClassInfoTests).FullName}.DummyTestClass.ClassCleanupMethod",
$"Value: {classCleanupException.Message}");
#endif
}

public async Task RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions()
Expand Down Expand Up @@ -667,8 +655,16 @@ public class DummyTestClass

public TestContext TestContext { get; set; } = null!;

// On .NET Framework, the JIT aggressively inlines small methods in Release mode,
// which removes stack frames. NoInlining ensures the method appears in stack traces.
#if NETFRAMEWORK
[MethodImpl(MethodImplOptions.NoInlining)]
#endif
public static void ClassInitializeMethod(TestContext testContext) => ClassInitializeMethodBody?.Invoke(testContext);

#if NETFRAMEWORK
[MethodImpl(MethodImplOptions.NoInlining)]
#endif
public static void ClassCleanupMethod() => ClassCleanupMethodBody?.Invoke();
}

Expand Down
Loading