Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
{
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)
{
Expand All @@ -41,9 +37,9 @@
// Ensure that some tests are running in parallel, because otherwise the output just works correctly.
DateTimeOffset firstEnd = testResults.Min(t => t.EndTime);
bool someStartedBeforeFirstEnded = testResults.Where(t => t.EndTime != firstEnd).Any(t => firstEnd > t.StartTime);
someStartedBeforeFirstEnded.Should().BeTrue("Tests must run in parallel, but there were no other tests that started, before the first one ended.");

Check failure on line 40 in test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Windows Debug)

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs#L40

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs(40,1): error : Expected boolean to be True because Tests must run in parallel, but there were no other tests that started, before the first one ended., but found False.

ValidateOutputsAreNotMixed(testResults, "TestMethod1", ["TestMethod2", "TestMethod3"]);

Check failure on line 42 in test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Windows Release)

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs#L42

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs(42,1): error : Expected boolean to be True because Tests must run in parallel, but there were no other tests that started, before the first one ended., but found False.

Check failure on line 42 in test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs#L42

test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs(42,1): error : Expected boolean to be True because Tests must run in parallel, but there were no other tests that started, before the first one ended., but found False.
ValidateOutputsAreNotMixed(testResults, "TestMethod2", ["TestMethod1", "TestMethod3"]);
ValidateOutputsAreNotMixed(testResults, "TestMethod3", ["TestMethod1", "TestMethod2"]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@
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(

Check failure on line 150 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Windows Release)

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs#L150

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs(150,1): error : Object reference not set to an instance of an object.

Check failure on line 150 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs#L150

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs(150,1): error : Object reference not set to an instance of an object.
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
Verify(exception.InnerException!.GetType() == typeof(AssertFailedException));
}

Expand All @@ -164,10 +162,8 @@
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(

Check failure on line 165 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Windows Release)

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs#L165

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs(165,1): error : Object reference not set to an instance of an object.

Check failure on line 165 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs#L165

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs(165,1): error : Object reference not set to an instance of an object.
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException));
}

Expand All @@ -182,10 +178,8 @@
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.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
Verify(exception.InnerException!.GetType() == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
}
Expand All @@ -205,10 +199,8 @@
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,8 @@
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.<RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMethodWithNonAssertExceptions>", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMethodWithNonAssertExceptions>", StringComparison.Ordinal));
Verify(exception.InnerException!.GetType() == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
}
Expand All @@ -358,10 +356,8 @@
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(

Check failure on line 359 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Windows Release)

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs#L359

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs(359,1): error : Object reference not set to an instance of an object.

Check failure on line 359 in test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs#L359

test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs(359,1): error : Object reference not set to an instance of an object.
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
Verify(exception.InnerException!.GetType() == typeof(AssertFailedException));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<TestMethodInfoInvokeWhenTestThrowsReturnsExpectedResult>b__", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.<TestMethodInfoInvokeWhenTestThrowsReturnsExpectedResult>b__", StringComparison.Ordinal));
}

public async Task TestInitialize_WhenTestReturnsTaskFromException_DisplayProperException()
Expand Down Expand Up @@ -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.<TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedResult>b__", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.<TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedResult>b__", StringComparison.Ordinal));
}

public async Task TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExpectedResult()
Expand Down Expand Up @@ -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.<TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExpectedResult>b__", StringComparison.Ordinal));
#endif
}

#endregion
Expand Down Expand Up @@ -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.<TestMethodInfoInvokeWhenTestCleanupThrowsReturnsExpectedResult>b__", StringComparison.Ordinal));
#endif
}

public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveReturnsExpectedResult()
Expand All @@ -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.<TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveReturnsExpectedResult>b__", StringComparison.Ordinal));
#endif
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests.<>c.<TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveReturnsExpectedResult>b__", StringComparison.Ordinal));
}

public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertFailedReturnsExpectedResult()
Expand Down
2 changes: 0 additions & 2 deletions test/Utilities/Automation.CLI/CLITestBase.e2e.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
}

Expand Down
Loading