-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat: add DisplayName property for dynamic tests #4058
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
PR Review: Add DisplayName Property for Dynamic TestsSummaryThis PR adds support for custom display names for dynamic tests, allowing users to specify a ✅ Strengths1. Excellent Dual-Mode ImplementationThe PR correctly implements the feature for both execution modes:
This follows Rule 1 from CLAUDE.md perfectly. 2. Code ConsolidationThe PR eliminates significant code duplication by unifying three separate metadata implementations:
Net result: -232 deletions, +260 additions = cleaner, more maintainable codebase. 3. Proper Snapshot Updates✅ All 4 public API snapshot files updated correctly (DotNet8_0, DotNet9_0, DotNet10_0, Net4_7) 4. Good Test CoverageThe new
5. Backward CompatibilityThe 🔍 Potential Issues & Suggestions1. Missing TestClassInstanceFactory in Reflection Mode
|
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 adds the ability to set custom display names for dynamic tests created via the DynamicTest<T> class. Previously, dynamic tests could only use auto-generated display names based on the test method name; now they can have human-readable custom names specified at test creation time.
Key changes:
- Added
DisplayNameproperty to theIDynamicTestMetadatainterface andDynamicTest<T>class - Created unified
DynamicTestMetadataclass to consolidate dynamic test metadata handling across AOT/source-generated and reflection modes - Updated test execution pipeline to honor custom display names when provided
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| TUnit.Core/IDynamicTestMetadata.cs | Added DisplayName property to the interface for dynamic test metadata |
| TUnit.Core/AbstractDynamicTest.cs | Added DisplayName property to DynamicTest<T> and propagated it to DynamicDiscoveryResult |
| TUnit.Core/DynamicTestMetadata.cs | New unified metadata class for dynamic tests that consolidates logic from three separate implementations (AOT, Reflection, TestRegistry) |
| TUnit.Engine/Services/TestRegistry.cs | Replaced RuntimeDynamicTestMetadata with unified DynamicTestMetadata class |
| TUnit.Engine/Discovery/ReflectionTestDataCollector.cs | Replaced DynamicReflectionTestMetadata with unified DynamicTestMetadata class |
| TUnit.Engine/Building/Collectors/AotTestDataCollector.cs | Replaced AotDynamicTestMetadata with unified DynamicTestMetadata class |
| TUnit.Engine/Building/TestBuilderPipeline.cs | Updated to use custom DisplayName when building dynamic tests |
| TUnit.TestProject/DynamicTests/DynamicTestDisplayNameTests.cs | Integration tests validating custom display names work correctly for dynamic tests |
| TUnit.PublicAPI/*.verified.txt | Updated public API snapshots across all .NET versions to reflect new DisplayName property |
| if (dynamicMetadata.DisplayName != null) | ||
| { | ||
| context.Metadata.DisplayName = dynamicMetadata.DisplayName; | ||
| } |
Copilot
AI
Dec 11, 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.
This code block sets the DisplayName on the context.Metadata, but this seems redundant because the same DisplayName value is already being passed to CreateExecutableTestFactory through the ExecutableTestCreationContext on line 343. The DynamicTestMetadata.CreateExecutableTest method already handles setting the display name via the DisplayName property passed in the context parameter (line 49 in DynamicTestMetadata.cs).
Consider removing this redundant assignment since the DisplayName is already properly propagated through the ExecutableTestCreationContext. This would simplify the code and avoid setting the same value twice through different paths.
| if (dynamicMetadata.DisplayName != null) | |
| { | |
| context.Metadata.DisplayName = dynamicMetadata.DisplayName; | |
| } |
No description provided.