-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix inherited test categories issue in source generation mode #2881
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
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…ation Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
@copilot In InheritedCategoryTestValidation , let's do something like
|
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Updated InheritedCategoryTestValidation to use the suggested assertion pattern. The tests now properly verify that inherited categories are preserved using |
Claude finished @Copilot's task —— View job Pull Request ReviewReviewing PR #2881 - Fix inherited test categories issue in source generation mode Todo List:
Review SummaryThis PR successfully addresses the issue where inherited test methods from base classes in different projects lose their category attributes during source generation mode. The fix is well-implemented and maintains parity between source generation and reflection modes. ✅ Code Quality & Best PracticesExcellent Implementation:
Strong Error Handling:
✅ Technical CorrectnessCore Fix Analysis:
Generated Code Quality:
✅ Test CoverageComprehensive Test Strategy:
Test Quality:
✅ Performance ConsiderationsEfficient Implementation:
✅ Security ConsiderationsNo Security Concerns Identified:
🔍 Minor ObservationsCode Clarity:
Edge Case Handling:
🎯 Recommendations
📋 Final AssessmentThis is a high-quality fix that:
The implementation demonstrates deep understanding of the Roslyn API and properly handles the complexity of cross-assembly attribute processing during source generation. Recommendation: APPROVE ✅ |
TUnit.Core.SourceGenerator.Tests/InheritedTestsFromDifferentProjectTests.cs
Show resolved
Hide resolved
…ojectTests.cs Co-authored-by: Stuart Lang <stuart.b.lang@gmail.com>
When using the
[InheritsTests]
attribute to inherit test methods from base classes in different projects, the categories on those inherited test methods were lost during source generation mode. This worked correctly in reflection mode, creating an inconsistency between the two execution modes.Problem
Consider this scenario:
In source generation mode, the
BaseTest
method would lose itsBaseCategory
attribute when inherited, but in reflection mode it would retain it correctly.Root Cause
The issue was in
AttributeWriter.WriteAttributes()
where attributes without anApplicationSyntaxReference
were being skipped entirely. This occurs for attributes from different assemblies/projects during compilation, which is exactly the case for inherited test methods from base classes in different projects.Solution
WriteAttributes()
to include attributes from other assemblies that have a validAttributeClass
WriteAttribute()
to handle both syntax-based attributes (current compilation) and metadata-based attributes (cross-assembly)WriteAttributeWithoutSyntax()
to properly reconstruct attributes using compilation metadataThe fix ensures that a
CategoryAttribute("BaseCategory")
from an inherited method now correctly generates:This maintains behavioral parity between source generation and reflection modes, ensuring inherited test categories are preserved regardless of which execution mode is used.
Fixes #2880.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.