Sitelet https://github.com/microsoft/testfx/pull/5070
Skip to content

Fix ClassCleanup not called when the first test in class is ignored - #5070

Merged
Youssef Fahmy (Youssef1313) merged 3 commits into
microsoft:mainfrom
Youssef1313:fix-classcleanup-not-called
Feb 19, 2025
Merged

Youssef Fahmy (Youssef1313) merged 3 commits into
microsoft:mainfrom
Youssef1313:fix-classcleanup-not-called

Conversation

@Youssef1313

@Youssef1313 Youssef Fahmy (Youssef1313) commented Feb 19, 2025 •

Copy link
Copy Markdown
Member

When the first test of a class is ignored (and the first test ever in the assembly), we will not call AssemblyInitialize, so IsAssemblyInitializeExecuted will be false.

However, in that case, we still want to call RunClassCleanup so that the test is marked as completed (see MarkTestComplete). Not marking the ignored test as completed is problematic, because later on when all tests in the class are executed, we will still be viewing remaining tests in the class, hence we will not call class cleanup.

Note that even with this change, we respect the case where all tests in class are ignored, and we will not call ClassCleanup. The logic in ExecuteClassCleanup handles the case when class init wasn't called.

Fixes #5062

@microsoft-github-policy-service microsoft-github-policy-service Bot added the area/fixtures Test class / assembly initialization & cleanup. label Feb 19, 2025
@Youssef1313

Copy link
Copy Markdown
Member Author

/backport to rel/3.8

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to rel/3.8: https://github.com/microsoft/testfx/actions/runs/13408191594

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting a comment on the test so we don't change order without noticing impact

…eTests.cs

Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/fixtures Test class / assembly initialization & cleanup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClassCleanup is not executed when Ignore (Attribute) is applied to the first test method in a series of test methods in a test class

2 participants