Fix skipped tests executing constructors by using placeholder instance#2723
Merged
Fix skipped tests executing constructors by using placeholder instance#2723
Conversation
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot stopped work on behalf of
thomhurst due to an error
August 3, 2025 23:13
Owner
|
@copilot retry |
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Contributor
Author
I've continued working on the fix and made significant progress. The issue where skipped tests still executed constructors has been resolved using a Key changes in commit 27439b6:
Verification: The fix now successfully prevents constructor execution for skipped tests while maintaining existing functionality for non-skipped tests. |
Copilot
AI
changed the title
[WIP] Skipped tests still execute test constructor
Fix skipped tests executing constructors by using placeholder instance
Aug 4, 2025
This was referenced Aug 6, 2025
Open
This was referenced Sep 22, 2025
This was referenced Sep 29, 2025
This was referenced Oct 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes issue where test constructors were being called even for tests marked with
[Skip]attribute, which could cause unwanted side effects or performance issues.Problem
Test instances were created unconditionally during the test building phase in
TestBuilder.CreateInstance(), regardless of whether the test had a[Skip]attribute. The skip check only happened later during test execution inSingleTestExecutor, meaning constructors ran unnecessarily for skipped tests.Solution
TestBuilderto check for basicSkipAttributeinstances during test discoverySkippedTestInstanceas a type-safe placeholder to avoid null reference issues while preventing constructor executionSingleTestExecutorto handle pre-skipped testsKey Changes
TUnit.Core/SkippedTestInstance.cs- New singleton placeholder classTUnit.Engine/Building/TestBuilder.cs- Early skip detection logicTesting
Verified that:
[Skip]attributed testsFixes #2562
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.