-
-
Notifications
You must be signed in to change notification settings - Fork 109
feat: add NotDiscoverableAttribute to hide tests from discovery #4154
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
Conversation
Pull Request Review: NotDiscoverableAttribute ImplementationOverviewThis PR adds a [NotDiscoverable] attribute to hide tests from test discovery while still allowing execution via filters. The implementation follows TUnit's existing patterns (similar to SkipAttribute) and is well-structured. Strengths
Observations & Considerations1. Dual-Mode ImplementationAccording to CLAUDE.md Rule 1, features must work in both source-generated and reflection modes. Analysis: This feature is correctly implemented:
Verdict: No additional source generator changes needed - the implementation is inherently dual-mode compatible. 2. Reason Property InconsistencyIssue: NotDiscoverableAttribute.Reason is nullable and optional, but SkipAttribute.Reason is required. Question: Is the Reason property actually used anywhere? If for documentation only, the nullable optional approach makes sense. If consumed by tooling/reporting, consistency with SkipAttribute might be better. Current behavior: The reason is stored but never logged or reported (unlike Skip which shows in test results). 3. Test Execution BehaviorThe PR description states: "hides tests from test explorer/discovery while still allowing them to execute when run via filters" Question: Are there tests verifying that NotDiscoverable tests CAN still execute when targeted by filter? The current tests don't appear to verify execution behavior - they just exist as integration tests. 4. Performance
Verdict: No performance concerns. Testing GapsMissing Test Coverage:
RecommendationsRequired:
Suggested:
Consider:
Final VerdictStatus: Approved with minor suggestions This is a well-implemented feature that follows TUnit's conventions and patterns. The implementation is clean, performant, and properly integrated with the existing event system. Code Quality: 5/5 Great work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a [NotDiscoverable] attribute that allows tests to be hidden from test discovery/exploration while remaining executable when invoked directly or via filters. This is useful for infrastructure tests, internal test helpers, or tests that should only run as dependencies.
Key Changes:
- Added
NotDiscoverableAttributewith optional reason parameter and extensible conditional hiding viaShouldHide()override - Modified test discovery pipeline to skip publishing hidden tests to test explorers
- Extended
ITestExecutioninterface withIsNotDiscoverableproperty for runtime test visibility control
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| TUnit.Core/Attributes/TestMetadata/NotDiscoverableAttribute.cs | Implements the new attribute with support for conditional hiding and documentation |
| TUnit.Core/Interfaces/ITestExecution.cs | Adds IsNotDiscoverable property to the test execution interface |
| TUnit.Core/TestContext.Execution.cs | Implements the IsNotDiscoverable property in TestContext |
| TUnit.Engine/TUnitMessageBus.cs | Modifies discovery logic to skip publishing tests marked as not discoverable |
| TUnit.TestProject/NotDiscoverableTests.cs | Adds integration tests demonstrating method-level, class-level, and conditional usage |
| TUnit.PublicAPI/*.verified.txt | Updates public API snapshots across .NET 4.7, 8.0, 9.0, and 10.0 to reflect new API surface |
| /// { | ||
| /// public NotDiscoverableOnCIAttribute() : base("Hidden on CI") { } | ||
| /// | ||
| /// public override Task<bool> ShouldHide(TestRegisteredContext context) |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTML entity '<' should be '<' in the code documentation example.
| /// public override Task<bool> ShouldHide(TestRegisteredContext context) | |
| /// public override Task<bool> ShouldHide(TestRegisteredContext context) |
Summary
[NotDiscoverable]attribute that hides tests from test explorer/discovery while still allowing them to execute when run via filtersChanges
IsNotDiscoverableproperty toTestContextandITestExecutioninterfaceNotDiscoverableAttributewith optional reason and conditionalShouldHide()overrideTUnitMessageBus.Discovered()to skip publishing for hidden testsUsage
Test plan
[NotDiscoverable][NotDiscoverable]🤖 Generated with Claude Code