From e5b5740f6e5e502f349274b14571ff30d4cb05b4 Mon Sep 17 00:00:00 2001 From: Engy Date: Tue, 13 Dec 2022 09:35:53 +0200 Subject: [PATCH 1/8] add tests --- .../Smoke.E2E.Tests/SuiteLifeCycleTests.cs | 243 +++++++++++++++++- ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 71 +++++ ...feCycleClassCleanupEndOfAssemblyAndNone.cs | 71 +++++ ...anupEndOfClassAndBeforeEachDerivedClass.cs | 71 +++++ .../LifeCycleClassCleanupEndOfClassAndNone.cs | 71 +++++ ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 50 ++++ ...DerivedClassCleanupEndOfAssemblyAndNone.cs | 50 ++++ ...anupEndOfClassAndBeforeEachDerivedClass.cs | 50 ++++ ...cleDerivedClassCleanupEndOfClassAndNone.cs | 50 ++++ 9 files changed, 724 insertions(+), 3 deletions(-) create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs diff --git a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs index d54894e98d..8ace517fbd 100644 --- a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs +++ b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs @@ -25,7 +25,7 @@ public void ValidateTestRunLifecycle_net462() private void ValidateTestRunLifecycle(string targetFramework) { InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly }, targetFramework: targetFramework); - RunEventsHandler.PassedTests.Should().HaveCount(15); // The inherit class tests are called twice. + RunEventsHandler.PassedTests.Should().HaveCount(27); // The inherit class tests are called twice. var caseClassCleanup = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanup.TestMethod")); caseClassCleanup.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); @@ -46,7 +46,7 @@ LifeCycleClassCleanup.TestCleanup was called """); - var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly")); + var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly.TestMethod")); caseClassCleanupEndOfAssembly.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); // We don't see "LifeCycleClassCleanupEndOfAssembly.ClassCleanup was called" because it will be attached to the @@ -67,7 +67,7 @@ LifeCycleClassCleanupEndOfAssembly.TestCleanup was called """); - var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass")); + var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass.TestMethod")); caseClassCleanupEndOfClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); caseClassCleanupEndOfClass.Messages.Single().Text.Should().Be( $""" @@ -307,6 +307,243 @@ LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.TestCleanup wa """); + var caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); + caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod")); + caseClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + + // Class cleanup with EndOfClass will appear in the parent logs in case of any inheritance behavior. + var caseClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); + caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called + + """); + + var caseClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndNone.TestMethod")); + caseClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod")); + caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + + """); + // Test the parent test method. // We are seeing all the ClassCleanup EndOfAssembly (or nothing set - as it's the default) being reported // here as this is the last test to run. diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..57c3c7c30f --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs @@ -0,0 +1,71 @@ +// 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; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfAssembly)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs new file mode 100644 index 0000000000..699163e489 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs @@ -0,0 +1,71 @@ +// 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; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfAssemblyAndNone : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfAssemblyAndNone() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..be60722f19 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs @@ -0,0 +1,71 @@ +// 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; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfClass)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs new file mode 100644 index 0000000000..bfbc140a90 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs @@ -0,0 +1,71 @@ +// 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; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfClassAndNone : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfClassAndNone() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(ClassCleanupBehavior.EndOfClass)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..15a9d3071f --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs new file mode 100644 index 0000000000..710510b396 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndNone : LifeCycleClassCleanupEndOfAssemblyAndNone +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfAssemblyAndNone() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..145faeaa24 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs new file mode 100644 index 0000000000..083173a9e3 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfClassAndNone : LifeCycleClassCleanupEndOfClassAndNone +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfClassAndNone() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassCleanup was called"); + } +} From ba6500d1a79c5e0a4e1a38fc62d3e9e4603027ed Mon Sep 17 00:00:00 2001 From: Engy Date: Tue, 13 Dec 2022 17:05:37 +0200 Subject: [PATCH 2/8] Revert "add tests" This reverts commit e5b5740f6e5e502f349274b14571ff30d4cb05b4. --- .../Smoke.E2E.Tests/SuiteLifeCycleTests.cs | 243 +----------------- ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 71 ----- ...feCycleClassCleanupEndOfAssemblyAndNone.cs | 71 ----- ...anupEndOfClassAndBeforeEachDerivedClass.cs | 71 ----- .../LifeCycleClassCleanupEndOfClassAndNone.cs | 71 ----- ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 50 ---- ...DerivedClassCleanupEndOfAssemblyAndNone.cs | 50 ---- ...anupEndOfClassAndBeforeEachDerivedClass.cs | 50 ---- ...cleDerivedClassCleanupEndOfClassAndNone.cs | 50 ---- 9 files changed, 3 insertions(+), 724 deletions(-) delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs delete mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs diff --git a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs index 8ace517fbd..d54894e98d 100644 --- a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs +++ b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs @@ -25,7 +25,7 @@ public void ValidateTestRunLifecycle_net462() private void ValidateTestRunLifecycle(string targetFramework) { InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly }, targetFramework: targetFramework); - RunEventsHandler.PassedTests.Should().HaveCount(27); // The inherit class tests are called twice. + RunEventsHandler.PassedTests.Should().HaveCount(15); // The inherit class tests are called twice. var caseClassCleanup = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanup.TestMethod")); caseClassCleanup.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); @@ -46,7 +46,7 @@ LifeCycleClassCleanup.TestCleanup was called """); - var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly.TestMethod")); + var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly")); caseClassCleanupEndOfAssembly.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); // We don't see "LifeCycleClassCleanupEndOfAssembly.ClassCleanup was called" because it will be attached to the @@ -67,7 +67,7 @@ LifeCycleClassCleanupEndOfAssembly.TestCleanup was called """); - var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass.TestMethod")); + var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass")); caseClassCleanupEndOfClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); caseClassCleanupEndOfClass.Messages.Single().Text.Should().Be( $""" @@ -307,243 +307,6 @@ LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.TestCleanup wa """); - var caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); - caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} - - """); - - var caseClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod")); - caseClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} - - """); - - // Class cleanup with EndOfClass will appear in the parent logs in case of any inheritance behavior. - var caseClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); - caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called - - """); - - var caseClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndNone.TestMethod")); - caseClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called - LifeCycleClassCleanupEndOfClassAndNone.ctor was called - LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called - LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called - LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} - LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called - - """); - - var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DerivedClassTestMethod")); - caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} - - """); - - var caseDerivedClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.DerivedClassTestMethod")); - caseDerivedClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} - - """); - var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.DerivedClassTestMethod")); - caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} - - """); - - var caseDerivedClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.DerivedClassTestMethod")); - caseDerivedClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called - LifeCycleClassCleanupEndOfClassAndNone.ctor was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called - LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called - LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} - - """); - - var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); - caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called - LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} - - """); - - var caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod")); - caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called - LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called - LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} - - """); - var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); - caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called - LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called - LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} - - """); - - var caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod")); - caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); - caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Messages.Single().Text.Should().Be( - $""" - - - TestContext Messages: - LifeCycleClassCleanupEndOfClassAndNone.ctor was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called - LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called - LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called - LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called - LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called - {(targetFramework == "net6.0" - ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" - : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} - - """); - // Test the parent test method. // We are seeing all the ClassCleanup EndOfAssembly (or nothing set - as it's the default) being reported // here as this is the last test to run. diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs deleted file mode 100644 index 57c3c7c30f..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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; -#if NET6_0_OR_GREATER -using System.Threading.Tasks; -#endif - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public class LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : IDisposable -#if NET6_0_OR_GREATER - , IAsyncDisposable -#endif -{ - private static TestContext s_testContext; - - public TestContext TestContext { get; set; } - - public LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); - } - - [TestInitialize] - public void TestInitialize() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); - } - - [TestMethod] - public void TestMethod() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); - } - - [TestCleanup] - public void TestCleanup() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); - } - - public void Dispose() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called"); - } - -#if NET6_0_OR_GREATER - public ValueTask DisposeAsync() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called"); - return ValueTask.CompletedTask; - } -#endif - - [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfAssembly)] - public static void ClassCleanup() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs deleted file mode 100644 index 699163e489..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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; -#if NET6_0_OR_GREATER -using System.Threading.Tasks; -#endif - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public class LifeCycleClassCleanupEndOfAssemblyAndNone : IDisposable -#if NET6_0_OR_GREATER - , IAsyncDisposable -#endif -{ - private static TestContext s_testContext; - - public TestContext TestContext { get; set; } - - public LifeCycleClassCleanupEndOfAssemblyAndNone() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); - } - - [TestInitialize] - public void TestInitialize() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); - } - - [TestMethod] - public void TestMethod() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called"); - } - - [TestCleanup] - public void TestCleanup() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); - } - - public void Dispose() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called"); - } - -#if NET6_0_OR_GREATER - public ValueTask DisposeAsync() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called"); - return ValueTask.CompletedTask; - } -#endif - - [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] - public static void ClassCleanup() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs deleted file mode 100644 index be60722f19..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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; -#if NET6_0_OR_GREATER -using System.Threading.Tasks; -#endif - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public class LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass : IDisposable -#if NET6_0_OR_GREATER - , IAsyncDisposable -#endif -{ - private static TestContext s_testContext; - - public TestContext TestContext { get; set; } - - public LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); - } - - [TestInitialize] - public void TestInitialize() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); - } - - [TestMethod] - public void TestMethod() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); - } - - [TestCleanup] - public void TestCleanup() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); - } - - public void Dispose() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called"); - } - -#if NET6_0_OR_GREATER - public ValueTask DisposeAsync() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called"); - return ValueTask.CompletedTask; - } -#endif - - [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfClass)] - public static void ClassCleanup() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs deleted file mode 100644 index bfbc140a90..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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; -#if NET6_0_OR_GREATER -using System.Threading.Tasks; -#endif - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public class LifeCycleClassCleanupEndOfClassAndNone : IDisposable -#if NET6_0_OR_GREATER - , IAsyncDisposable -#endif -{ - private static TestContext s_testContext; - - public TestContext TestContext { get; set; } - - public LifeCycleClassCleanupEndOfClassAndNone() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ctor was called"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called"); - } - - [TestInitialize] - public void TestInitialize() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called"); - } - - [TestMethod] - public void TestMethod() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called"); - } - - [TestCleanup] - public void TestCleanup() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called"); - } - - public void Dispose() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.Dispose was called"); - } - -#if NET6_0_OR_GREATER - public ValueTask DisposeAsync() - { - TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called"); - return ValueTask.CompletedTask; - } -#endif - - [ClassCleanup(ClassCleanupBehavior.EndOfClass)] - public static void ClassCleanup() - { - s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs deleted file mode 100644 index 15a9d3071f..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass -{ - private static TestContext s_testContext; - - public TestContext DerivedClassTestContext { get; set; } - - public LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); - } - - [ClassInitialize] - public static void DerivedClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); - } - - [TestInitialize] - public void DerivedClassTestInitialize() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); - } - - [TestMethod] - public void DerivedClassTestMethod() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); - } - - [TestCleanup] - public void DerivedClassTestCleanup() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); - } - - [ClassCleanup] - public static void DerivedClassCleanup() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs deleted file mode 100644 index 710510b396..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndNone : LifeCycleClassCleanupEndOfAssemblyAndNone -{ - private static TestContext s_testContext; - - public TestContext DerivedClassTestContext { get; set; } - - public LifeCycleDerivedClassCleanupEndOfAssemblyAndNone() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called"); - } - - [ClassInitialize] - public static void DerivedClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); - } - - [TestInitialize] - public void DerivedClassTestInitialize() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); - } - - [TestMethod] - public void DerivedClassTestMethod() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called"); - } - - [TestCleanup] - public void DerivedClassTestCleanup() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); - } - - [ClassCleanup] - public static void DerivedClassCleanup() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs deleted file mode 100644 index 145faeaa24..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public sealed class LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass -{ - private static TestContext s_testContext; - - public TestContext DerivedClassTestContext { get; set; } - - public LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); - } - - [ClassInitialize] - public static void DerivedClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); - } - - [TestInitialize] - public void DerivedClassTestInitialize() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); - } - - [TestMethod] - public void DerivedClassTestMethod() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); - } - - [TestCleanup] - public void DerivedClassTestCleanup() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); - } - - [ClassCleanup] - public static void DerivedClassCleanup() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); - } -} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs deleted file mode 100644 index 083173a9e3..0000000000 --- a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SuiteLifeCycleTestProject; - -[TestClass] -public sealed class LifeCycleDerivedClassCleanupEndOfClassAndNone : LifeCycleClassCleanupEndOfClassAndNone -{ - private static TestContext s_testContext; - - public TestContext DerivedClassTestContext { get; set; } - - public LifeCycleDerivedClassCleanupEndOfClassAndNone() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called"); - } - - [ClassInitialize] - public static void DerivedClassInitialize(TestContext testContext) - { - s_testContext = testContext; - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called"); - } - - [TestInitialize] - public void DerivedClassTestInitialize() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called"); - } - - [TestMethod] - public void DerivedClassTestMethod() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called"); - } - - [TestCleanup] - public void DerivedClassTestCleanup() - { - TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called"); - } - - [ClassCleanup] - public static void DerivedClassCleanup() - { - s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassCleanup was called"); - } -} From 47536679552f26a85d5ab41f3308213530b49711 Mon Sep 17 00:00:00 2001 From: Engy Date: Thu, 5 Jan 2023 02:06:28 +0100 Subject: [PATCH 3/8] Change ClassCleanup default behavior to be "EndOfClass" --- src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs | 2 +- .../MSTest.TestAdapter/Execution/UnitTestRunner.cs | 2 +- .../MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt | 1 - .../MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt | 1 + .../Attributes/Lifecycle/Cleanup/ClassCleanupBehavior.cs | 8 ++++---- .../Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs | 2 +- .../TestFramework/PublicAPI/PublicAPI.Shipped.txt | 2 -- .../TestFramework/PublicAPI/PublicAPI.Unshipped.txt | 2 ++ .../SuiteLifeCycleTests.cs | 8 ++++---- ...ycleClassInitializeAndCleanupBeforeEachDerivedClass.cs | 2 +- .../LifeCycleClassInitializeAndCleanupNone.cs | 2 +- ...InitializeBeforeEachDerivedClassAndClassCleanupNone.cs | 2 +- ...InitializeNoneAndClassCleanupBeforeEachDerivedClass.cs | 2 +- ...dClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs | 2 +- .../LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs | 2 +- ...ivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs | 2 +- .../LifeCycleDerivedClassCleanupEndOfClassAndNone.cs | 2 +- ...ivedClassInitializeAndCleanupBeforeEachDerivedClass.cs | 2 +- .../LifeCycleDerivedClassInitializeAndCleanupNone.cs | 2 +- ...InitializeBeforeEachDerivedClassAndClassCleanupNone.cs | 2 +- ...InitializeNoneAndClassCleanupBeforeEachDerivedClass.cs | 2 +- 21 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs index f5f444bd8d..5480c83fac 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs @@ -330,7 +330,7 @@ public void RunClassInitialize(TestContext testContext) /// /// Any exception that can be thrown as part of a class cleanup as warning messages. /// - public string? RunClassCleanup(ClassCleanupBehavior classCleanupLifecycle = ClassCleanupBehavior.EndOfAssembly) + public string? RunClassCleanup(ClassCleanupBehavior classCleanupLifecycle = ClassCleanupBehavior.EndOfClass) { if (ClassCleanupMethod is null && BaseClassInitAndCleanupMethods.All(p => p.Item2 == null)) { diff --git a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs index 8e53db7412..b08e570de5 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs @@ -90,7 +90,7 @@ internal void InitializeClassCleanupManager(ICollection testsTo { // We can't transport the Enum across AppDomain boundaries because of backwards and forwards compatibility. // So we're converting here if we can, or falling back to the default. - var lifecycle = ClassCleanupBehavior.EndOfAssembly; + var lifecycle = ClassCleanupBehavior.EndOfClass; if (classCleanupLifecycle != null && Enum.IsDefined(typeof(ClassCleanupBehavior), classCleanupLifecycle)) { lifecycle = (ClassCleanupBehavior)classCleanupLifecycle; diff --git a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt index d83434a5ad..2eee1d3349 100644 --- a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt @@ -38,7 +38,6 @@ Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.H Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.IsClassCleanupExecuted.get -> bool Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.IsClassInitializeExecuted.get -> bool Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.Parent.get -> Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo! -Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfAssembly) -> string? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassInitialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext! testContext) -> void Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.TestCleanupMethod.get -> System.Reflection.MethodInfo? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.TestContextProperty.get -> System.Reflection.PropertyInfo? diff --git a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt index ab058de62d..1a0a72f023 100644 --- a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt @@ -1 +1,2 @@ #nullable enable +Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass) -> string? diff --git a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupBehavior.cs b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupBehavior.cs index 7f829f43ef..a39e837b4f 100644 --- a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupBehavior.cs +++ b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupBehavior.cs @@ -9,12 +9,12 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; public enum ClassCleanupBehavior { /// - /// Run at end of assembly. + /// Run at end of class. /// - EndOfAssembly, + EndOfClass, /// - /// Run at end of class. + /// Run at end of assembly. /// - EndOfClass, + EndOfAssembly, } diff --git a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs index 1387c67564..189165bd29 100644 --- a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs @@ -14,7 +14,7 @@ public class ClassCleanupExecutionAttribute : Attribute /// /// Default class cleanup execution. /// - public static readonly ClassCleanupBehavior DefaultClassCleanupLifecycle = ClassCleanupBehavior.EndOfAssembly; + public static readonly ClassCleanupBehavior DefaultClassCleanupLifecycle = ClassCleanupBehavior.EndOfClass; /// /// Initializes a new instance of the class. diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt index 2d2feb3767..b511f3c6a2 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt @@ -22,8 +22,6 @@ Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.ClassCleanupA Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.CleanupBehavior.get -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior? Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.InheritanceBehavior.get -> Microsoft.VisualStudio.TestTools.UnitTesting.InheritanceBehavior Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior -Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfAssembly = 0 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior -Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass = 1 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute.ClassCleanupExecutionAttribute() -> void Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute.ClassCleanupExecutionAttribute(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior cleanupBehavior) -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 646944d390..332546ae59 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,4 +1,6 @@ #nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfAssembly = 1 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior +Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass = 0 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute() -> void Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? arg1) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? arg1, object? arg2) -> void diff --git a/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs b/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs index 41a3f506c2..65a58920df 100644 --- a/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs +++ b/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs @@ -167,6 +167,7 @@ private void ValidateTestRunLifecycle(string targetFramework) {(targetFramework == "net6.0" ? "Console: LifeCycleClassCleanup.DisposeAsync was called\r\nConsole: LifeCycleClassCleanup.Dispose was called" : "Console: LifeCycleClassCleanup.Dispose was called")} + Console: LifeCycleClassCleanup.ClassCleanup was called """); caseClassCleanup.Messages[1].Text.Should().Be( @@ -185,7 +186,8 @@ private void ValidateTestRunLifecycle(string targetFramework) + "\r\n" + GenerateTraceDebugPrefixedMessage("LifeCycleClassCleanup.Dispose was called") : GenerateTraceDebugPrefixedMessage("LifeCycleClassCleanup.Dispose was called"))} - + {GenerateTraceDebugPrefixedMessage("LifeCycleClassCleanup.ClassCleanup was called")} + """); caseClassCleanup.Messages[2].Text.Should().Be( $""" @@ -201,6 +203,7 @@ LifeCycleClassCleanup.TestCleanup was called {(targetFramework == "net6.0" ? "LifeCycleClassCleanup.DisposeAsync was called\r\nLifeCycleClassCleanup.Dispose was called" : "LifeCycleClassCleanup.Dispose was called")} + LifeCycleClassCleanup.ClassCleanup was called """); @@ -1568,7 +1571,6 @@ LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called var expectedRemainingMessages = """ Console: LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called - Console: LifeCycleClassCleanup.ClassCleanup was called Console: LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called Console: LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called Console: LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassCleanup was called @@ -1624,7 +1626,6 @@ LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called {GenerateTraceDebugPrefixedMessage("LifeCycleClassInitializeAndCleanupNone.ClassCleanup was called")} {GenerateTraceDebugPrefixedMessage("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassCleanup was called")} {GenerateTraceDebugPrefixedMessage("LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.ClassCleanup was called")} - {GenerateTraceDebugPrefixedMessage("LifeCycleClassCleanup.ClassCleanup was called")} {GenerateTraceDebugPrefixedMessage("LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called")} {GenerateTraceDebugPrefixedMessage("LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.ClassCleanup was called")} {GenerateTraceDebugPrefixedMessage("LifeCycleDerivedClassInitializeAndCleanupNone.ClassCleanup was called")} @@ -1676,7 +1677,6 @@ LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassCleanup was called LifeCycleClassCleanupEndOfAssemblyAndNone.ClassCleanup was called - LifeCycleClassCleanup.ClassCleanup was called LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called LifeCycleDerivedClassInitializeAndCleanupNone.ClassCleanup was called LifeCycleClassInitializeAndCleanupNone.ClassCleanup was called diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupBeforeEachDerivedClass.cs index 3182b45aef..2c1b5bd694 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupBeforeEachDerivedClass.cs @@ -87,7 +87,7 @@ public ValueTask DisposeAsync() } #endif - [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass)] + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfAssembly)] public static void ClassCleanup() { s_testContext.WriteLine("LifeCycleClassInitializeAndCleanupBeforeEachDerivedClass.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupNone.cs index 888c57a8f6..4f7b807570 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeAndCleanupNone.cs @@ -87,7 +87,7 @@ public ValueTask DisposeAsync() } #endif - [ClassCleanup(InheritanceBehavior.None)] + [ClassCleanup(InheritanceBehavior.None, ClassCleanupBehavior.EndOfAssembly)] public static void ClassCleanup() { s_testContext.WriteLine("LifeCycleClassInitializeAndCleanupNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs index b1a5d179c5..19db618a9e 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs @@ -87,7 +87,7 @@ public ValueTask DisposeAsync() } #endif - [ClassCleanup(InheritanceBehavior.None)] + [ClassCleanup(InheritanceBehavior.None, ClassCleanupBehavior.EndOfAssembly)] public static void ClassCleanup() { s_testContext.WriteLine("LifeCycleClassInitializeBeforeEachDerivedClassAndClassCleanupNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs index be38a76fe6..8122f204d2 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs @@ -87,7 +87,7 @@ public ValueTask DisposeAsync() } #endif - [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass)] + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfAssembly)] public static void ClassCleanup() { s_testContext.WriteLine("LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs index d836891284..cd544c7406 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs index 62b95bab86..a7c27e8b04 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs index b03078b4e9..849463af7b 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs index 2e0be93a90..0e0cc9b262 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.cs index 80272222e8..ebf932e828 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassInitializeAndCleanupBeforeEachDerivedClass.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupNone.cs index fbfcdbe06b..54b9788c65 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeAndCleanupNone.cs @@ -60,7 +60,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassInitializeAndCleanupNone.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassInitializeAndCleanupNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs index 53c7479a06..22829e6324 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.cs @@ -61,7 +61,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassInitializeBeforeEachDerivedClassAndClassCleanupNone.ClassCleanup was called"); diff --git a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs index ef1d52805c..31c6fcbdff 100644 --- a/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs +++ b/test/IntegrationTests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.cs @@ -61,7 +61,7 @@ public void DerivedClassTestCleanup() Debug.WriteLine("Debug: LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.TestCleanup was called"); } - [ClassCleanup] + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] public static void DerivedClassCleanup() { s_testContext.WriteLine("LifeCycleDerivedClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.ClassCleanup was called"); From 69e69e64112f5bea1c6367bd4db18dd9fdb99605 Mon Sep 17 00:00:00 2001 From: Engy Date: Fri, 6 Jan 2023 11:35:40 +0100 Subject: [PATCH 4/8] fix unit tests --- .../Execution/TestClassInfoTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestClassInfoTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestClassInfoTests.cs index 64097fd886..8fe12a2b8d 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestClassInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestClassInfoTests.cs @@ -491,7 +491,7 @@ public void RunClassCleanupShouldReturnAssertFailureExceptionDetails() _testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.ClassCleanupMethod)); // Act - var classCleanup = _testClassInfo.RunClassCleanup(); + var classCleanup = _testClassInfo.RunClassCleanup(UTF.ClassCleanupBehavior.EndOfAssembly); // Assert Verify(classCleanup.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.")); @@ -506,7 +506,7 @@ public void RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails() _testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.ClassCleanupMethod)); // Act - var classCleanup = _testClassInfo.RunClassCleanup(); + var classCleanup = _testClassInfo.RunClassCleanup(UTF.ClassCleanupBehavior.EndOfAssembly); // Assert Verify(classCleanup.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.")); @@ -521,7 +521,7 @@ public void RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions() _testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.ClassCleanupMethod)); // Act - var classCleanup = _testClassInfo.RunClassCleanup(); + var classCleanup = _testClassInfo.RunClassCleanup(UTF.ClassCleanupBehavior.EndOfAssembly); // Assert Verify(classCleanup.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.")); @@ -539,7 +539,7 @@ public void RunBaseClassCleanupWithNoDerivedClassCleanupShouldReturnExceptionDet _testClassInfo.BaseClassCleanupMethodsStack.Push(baseClassCleanupMethod); // Act - var classCleanup = _testClassInfo.RunClassCleanup(); + var classCleanup = _testClassInfo.RunClassCleanup(UTF.ClassCleanupBehavior.EndOfAssembly); // Assert Verify(classCleanup.StartsWith("Class Cleanup method DummyBaseTestClass.CleanupClassMethod failed.")); From 04e26f3be9ca993abe68dc176effa357cb0cdd4f Mon Sep 17 00:00:00 2001 From: Engy Date: Mon, 9 Jan 2023 13:01:42 +0100 Subject: [PATCH 5/8] move api back to shipped --- src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt | 1 + .../MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt index 2eee1d3349..c71b6442e8 100644 --- a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt @@ -15,6 +15,7 @@ Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListe Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListener.StandardError.get -> string! Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListener.StandardOutput.get -> string! Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo +Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass) -> string? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyCleanupMethod.get -> System.Reflection.MethodInfo? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyInitializationException.get -> System.Exception? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyInitializeMethod.get -> System.Reflection.MethodInfo? diff --git a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt index 1a0a72f023..91b0e1a43b 100644 --- a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Unshipped.txt @@ -1,2 +1 @@ -#nullable enable -Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass) -> string? +#nullable enable \ No newline at end of file From 03b816ce3df3241a7885fbc2f8779f5aa22ac608 Mon Sep 17 00:00:00 2001 From: Engy Date: Mon, 9 Jan 2023 13:03:43 +0100 Subject: [PATCH 6/8] remove unused property "DefaultClassCleanupLifecycle" --- .../Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs | 7 +------ .../TestFramework/PublicAPI/PublicAPI.Shipped.txt | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs index 189165bd29..1da0df830d 100644 --- a/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/Lifecycle/Cleanup/ClassCleanupExecutionAttribute.cs @@ -11,16 +11,11 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = true)] public class ClassCleanupExecutionAttribute : Attribute { - /// - /// Default class cleanup execution. - /// - public static readonly ClassCleanupBehavior DefaultClassCleanupLifecycle = ClassCleanupBehavior.EndOfClass; - /// /// Initializes a new instance of the class. /// public ClassCleanupExecutionAttribute() - : this(DefaultClassCleanupLifecycle) + : this(ClassCleanupBehavior.EndOfClass) { } diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt index b511f3c6a2..a3279434a5 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt @@ -324,7 +324,6 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.That.get -> static Microsoft.VisualStudio.TestTools.UnitTesting.Logging.Logger.LogMessage(string! format, params object?[]! args) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Logging.Logger.OnLogMessage -> Microsoft.VisualStudio.TestTools.UnitTesting.Logging.Logger.LogMessageHandler? static Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.That.get -> Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert! -static readonly Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute.DefaultClassCleanupLifecycle -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior static readonly Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute.DefaultDataAccessMethod -> Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod static readonly Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute.DefaultProviderName -> string! virtual Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.GetDisplayName(System.Reflection.MethodInfo! methodInfo, object?[]? data) -> string? From 274e729a75e7fa2b3033a1b7183654d3bb808fcc Mon Sep 17 00:00:00 2001 From: Engy Date: Mon, 9 Jan 2023 13:12:01 +0100 Subject: [PATCH 7/8] add a comment --- .../SuiteLifeCycleTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs b/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs index 65a58920df..bdeaff0280 100644 --- a/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs +++ b/test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/SuiteLifeCycleTests.cs @@ -153,6 +153,7 @@ private void ValidateTestRunLifecycle(string targetFramework) targetFramework: targetFramework); RunEventsHandler.PassedTests.Should().HaveCount(27); // The inherit class tests are called twice. + // The cleanup will appear in this case as the default ClassCleanup is EndOfClass. var caseClassCleanup = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanup.TestMethod")); caseClassCleanup.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); caseClassCleanup.Messages.Should().HaveCount(3); From 5d7808e97d887946dc57ef25f37f59af85d2c538 Mon Sep 17 00:00:00 2001 From: Engy Date: Tue, 10 Jan 2023 17:31:30 +0100 Subject: [PATCH 8/8] move apis to shipped files --- src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt | 2 +- src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt | 2 ++ .../TestFramework/PublicAPI/PublicAPI.Unshipped.txt | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt index c71b6442e8..896f3e561d 100644 --- a/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Adapter/MSTest.TestAdapter/PublicAPI/PublicAPI.Shipped.txt @@ -15,7 +15,6 @@ Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListe Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListener.StandardError.get -> string! Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.LogMessageListener.StandardOutput.get -> string! Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo -Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass) -> string? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyCleanupMethod.get -> System.Reflection.MethodInfo? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyInitializationException.get -> System.Exception? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.AssemblyInitializeMethod.get -> System.Reflection.MethodInfo? @@ -39,6 +38,7 @@ Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.H Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.IsClassCleanupExecuted.get -> bool Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.IsClassInitializeExecuted.get -> bool Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.Parent.get -> Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo! +Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior classCleanupLifecycle = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass) -> string? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassInitialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext! testContext) -> void Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.TestCleanupMethod.get -> System.Reflection.MethodInfo? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.TestContextProperty.get -> System.Reflection.PropertyInfo? diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt index a3279434a5..cd4707d305 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Shipped.txt @@ -22,6 +22,8 @@ Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.ClassCleanupA Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.CleanupBehavior.get -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior? Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute.InheritanceBehavior.get -> Microsoft.VisualStudio.TestTools.UnitTesting.InheritanceBehavior Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior +Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfAssembly = 1 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior +Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass = 0 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute.ClassCleanupExecutionAttribute() -> void Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupExecutionAttribute.ClassCleanupExecutionAttribute(Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior cleanupBehavior) -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 332546ae59..646944d390 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,6 +1,4 @@ #nullable enable -Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfAssembly = 1 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior -Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior.EndOfClass = 0 -> Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute() -> void Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? arg1) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? arg1, object? arg2) -> void