diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs b/src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs index 58ce8e0844..15dd32dc92 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs @@ -162,9 +162,12 @@ internal async Task RunSingleTestAsync(TestMethod testMethod, IDic testContextForClassCleanup = PlatformServiceProvider.Instance.GetTestContext(testMethod: null, testMethod.FullClassName, testContextProperties, messageLogger, testContextForTestExecution.Context.CurrentTestOutcome); _classCleanupManager.MarkTestComplete(testMethod, out bool isLastTestInClass); - if (isLastTestInClass && testMethodInfo is not null) + if (isLastTestInClass) { - await testMethodInfo.Parent.RunClassCleanupAsync(testContextForClassCleanup, result).ConfigureAwait(false); + if (testMethodInfo is not null) + { + await testMethodInfo.Parent.RunClassCleanupAsync(testContextForClassCleanup, result).ConfigureAwait(false); + } // Mark the class as complete when all class cleanups are complete. When all classes are complete we progress to running assembly cleanup. // Class is not complete until after all class cleanups are done, to prevent running assembly cleanup too early. diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs index b68db53c81..f82fd72139 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs @@ -76,8 +76,6 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture. [TestClass] public class TestClass1 { - public static bool ClassCleanupFinished { get; private set; } - [TestMethod] public void Test1() {