diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index fc8c2870ef..8d23758954 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -24,11 +24,18 @@ public sealed class TestApplication : ITestApplication private readonly IHost _host; private static UnhandledExceptionHandler? s_unhandledExceptionHandler; - static TestApplication() => + static TestApplication() + { // Capture system console soon as possible to avoid any other code from changing it. // This is important for the console display system to work properly. _ = new SystemConsole(); + // Enable portable PDBs for stack traces to match VSTest behavior + // This ensures stack traces are available in release builds when using portable PDBs + // See: https://github.com/dotnet/designs/blob/master/accepted/2020/diagnostics/debugging-with-symbols-and-sources.md#stack-traces + AppContext.SetSwitch("Switch.System.Diagnostics.IgnorePortablePDBsInStackTraces", false); + } + internal TestApplication(IHost host) => _host = host; // This cast looks like incorrect assumption. diff --git a/test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs b/test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs index c7720d0655..ca5c772bc7 100644 --- a/test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs +++ b/test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs @@ -14,11 +14,7 @@ public class OutputTests : CLITestBase { private const string TestAssetName = "OutputTestProject"; -#pragma warning disable IDE0051 // Remove unused private members - test is failing in CI. - private async Task OutputIsNotMixedWhenTestsRunInParallel() => await ValidateOutputForClassAsync("UnitTest1"); - - private async Task OutputIsNotMixedWhenAsyncTestsRunInParallel() => await ValidateOutputForClassAsync("UnitTest2"); -#pragma warning restore IDE0051 // Remove unused private members + public async Task OutputIsNotMixedWhenTestsRunInParallel() => await ValidateOutputForClassAsync("UnitTest1"); private static async Task ValidateOutputForClassAsync(string className) { diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs index e95b9c01cc..07cae1b85f 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs @@ -147,10 +147,8 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailur Verify( exception.Message == "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 Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.", StringComparison.Ordinal)); Verify(exception.InnerException!.GetType() == typeof(AssertFailedException)); } @@ -164,10 +162,8 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveO Verify( exception.Message == "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 Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.", StringComparison.Ordinal)); -#endif Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException)); } @@ -182,10 +178,8 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExce Verify( exception.Message == "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.ArgumentException: Some actualErrorMessage message. Aborting test execution."); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.", StringComparison.Ordinal)); Verify(exception.InnerException!.GetType() == typeof(ArgumentException)); Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException)); } @@ -205,10 +199,8 @@ public void RunAssemblyInitializeShouldThrowTheInnerMostExceptionWhenThereAreMul Verify( exception.Message == "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.InvalidOperationException: I fail.. Aborting test execution."); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.FailingStaticHelper..cctor()", StringComparison.Ordinal)); -#endif Verify(exception.InnerException!.GetType() == typeof(InvalidOperationException)); } diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs index 9242df3d9f..f4157d52c6 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs @@ -338,10 +338,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMeth Verify( exception.Message == "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.InitBaseClassMethod threw exception. System.ArgumentException: Some exception message."); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.", StringComparison.Ordinal)); Verify(exception.InnerException!.GetType() == typeof(ArgumentException)); Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException)); } @@ -358,10 +356,8 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure() Verify( exception.Message == "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 Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.", StringComparison.Ordinal)); Verify(exception.InnerException!.GetType() == typeof(AssertFailedException)); } diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs index a6f7dea1cc..ecdbcdcf14 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs @@ -576,10 +576,8 @@ public async Task TestMethodInfoInvokeWhenTestThrowsReturnsExpectedResult() Verify(exception.Outcome == UTF.UnitTestOutcome.Failed); Verify(exception.InnerException!.GetType() == typeof(ArgumentException)); Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException)); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); } public async Task TestInitialize_WhenTestReturnsTaskFromException_DisplayProperException() @@ -646,10 +644,8 @@ public async Task TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedRes Verify(errorMessage == exception.Message); Verify(exception.Outcome == UTF.UnitTestOutcome.Failed); Verify(exception.InnerException!.GetType() == typeof(AssertFailedException)); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); } public async Task TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExpectedResult() @@ -682,10 +678,8 @@ public async Task TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExp Verify(errorMessage == exception.Message); Verify(exception.Outcome == UTF.UnitTestOutcome.Inconclusive); Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException)); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); -#endif } #endregion @@ -832,10 +826,8 @@ public async Task TestMethodInfoInvokeWhenTestCleanupThrowsReturnsExpectedResult Verify(exception.InnerException!.GetType() == typeof(ArgumentException)); Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException)); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); -#endif } public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveReturnsExpectedResult() @@ -859,10 +851,8 @@ public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveRet Verify(exception.Outcome == UTF.UnitTestOutcome.Inconclusive); Verify(expectedErrorMessage == exception.Message); Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException)); -#if DEBUG Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith( - " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); -#endif + " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.b__", StringComparison.Ordinal)); } public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertFailedReturnsExpectedResult() diff --git a/test/Utilities/Automation.CLI/CLITestBase.e2e.cs b/test/Utilities/Automation.CLI/CLITestBase.e2e.cs index f49ad93ef1..4ec41c0228 100644 --- a/test/Utilities/Automation.CLI/CLITestBase.e2e.cs +++ b/test/Utilities/Automation.CLI/CLITestBase.e2e.cs @@ -248,7 +248,6 @@ public void ValidateFailedTestsContain(bool validateStackTraceInfo, params strin test.Equals(f.DisplayName, StringComparison.Ordinal)); testFound.Should().NotBeNull("Test '{0}' does not appear in failed tests list.", test); -#if DEBUG if (!validateStackTraceInfo) { continue; @@ -261,7 +260,6 @@ public void ValidateFailedTestsContain(bool validateStackTraceInfo, params strin { testFound.ErrorStackTrace.Should().Contain(testMethodName, "No stack trace for failed test: {0}", test); } -#endif } }