Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rel/3.8] Fix ClassCleanup not called when the first test in class is ignored #5071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ TestResult DoRun()
// If ClassInitialize method has not been executed, then we should not execute ClassCleanup
// Note that if there is no ClassInitialze method at all, we will still set
// IsClassInitializeExecuted to true in RunClassInitialize
// IsClassInitializeExecuted can be false if all tests in the class are ignored.
|| !IsClassInitializeExecuted)
{
return null;
Expand Down
5 changes: 3 additions & 2 deletions src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ internal async Task<TestResult[]> RunSingleTestAsync(TestMethod testMethod, IDic
}
}

ITestContext testContextForClassCleanup = PlatformServiceProvider.Instance.GetTestContext(testMethod, writer, properties, messageLogger, testContextForTestExecution.Context.CurrentTestOutcome);
testMethodInfo?.Parent.RunClassCleanup(testContextForClassCleanup, _classCleanupManager, testMethodInfo, testMethod, result);

if (testMethodInfo?.Parent.Parent.IsAssemblyInitializeExecuted == true)
{
ITestContext testContextForClassCleanup = PlatformServiceProvider.Instance.GetTestContext(testMethod, writer, properties, messageLogger, testContextForTestExecution.Context.CurrentTestOutcome);
testMethodInfo.Parent.RunClassCleanup(testContextForClassCleanup, _classCleanupManager, testMethodInfo, testMethod, result);
ITestContext testContextForAssemblyCleanup = PlatformServiceProvider.Instance.GetTestContext(testMethod, writer, properties, messageLogger, testContextForClassCleanup.Context.CurrentTestOutcome);
RunAssemblyCleanupIfNeeded(testContextForAssemblyCleanup, _classCleanupManager, _typeCache, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public async Task ClassCleanup_Inheritance_WhenClassIsSkipped()

// Assert
testHostResult.AssertExitCodeIs(ExitCodes.Success);
testHostResult.AssertOutputContainsSummary(failed: 0, passed: 11, skipped: 7);
testHostResult.AssertOutputContainsSummary(failed: 0, passed: 11, skipped: 8);

testHostResult.AssertOutputContains("SubClass.Method");
testHostResult.AssertOutputContains("SubClass.ClassCleanup");
testHostResult.AssertOutputDoesNotContain("SubClass.IgnoredMethod");
}

[TestMethod]
Expand Down Expand Up @@ -191,6 +193,11 @@ public class SubClass : IntermediateClass
public static void SubClassCleanup()
=> Console.WriteLine("SubClass.ClassCleanup");

[TestMethod]
[Ignore]
public void IgnoredMethod()
=> Console.WriteLine("SubClass.IgnoredMethod");

[TestMethod]
public void Method()
=> Console.WriteLine("SubClass.Method");
Expand Down