Skip to content

Mark TestMetadataGenerator output with GeneratedCode attribute#4690

Merged
thomhurst merged 3 commits intomainfrom
copilot/mark-generated-code-attribute
Feb 6, 2026
Merged

Mark TestMetadataGenerator output with GeneratedCode attribute#4690
thomhurst merged 3 commits intomainfrom
copilot/mark-generated-code-attribute

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

The TestMetadataGenerator was not marking generated code with [GeneratedCode] or [ExcludeFromCodeCoverage] attributes, preventing code coverage tools from properly excluding it.

Changes

  • Added [GeneratedCode] and [ExcludeFromCodeCoverage] attributes to generated test metadata classes
  • Updated 86 snapshot tests to reflect the new output

Generated Code

Before:

namespace TUnit.Generated;
internal sealed class TUnit_MyTests_Test_TestSource : ITestSource
{

After:

namespace TUnit.Generated;
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("TUnit", "1.0.0.0")]
internal sealed class TUnit_MyTests_Test_TestSource : ITestSource
{

This aligns with existing patterns in InfrastructureGenerator and DynamicTestsGenerator.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Mark TestMetadataGenerator code with generated code attribute</issue_title>
<issue_description>### Description

The code generated by TUnit.Core.SourceGenerator.Generators.TestMetadataGenerator is not marked with the [GeneratedCode] attribute, which makes it harder to exclude from code coverage reports.

Expected Behavior

All code generated by source generators would be marked with [GeneratedCode]. If appropriate, it could also be marked with [ExcludeFromCodeCoverage] as well.

Actual Behavior

The code, which is generated in the TUnit.Generated namespace, is not marked with any attributes to signify it is auto-generated.

Steps to Reproduce

Use <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> in a project file to see the generated code and note it is not marked with attributes.

TUnit Version

1.13.0

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

Other (please specify in additional context)

Error Output / Stack Trace

Additional Context

This happens during build, not during test execution, although the impact mostly affects code coverage reports.

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ataGenerator output

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot AI changed the title [WIP] Mark TestMetadataGenerator code with generated code attribute Mark TestMetadataGenerator output with GeneratedCode attribute Feb 6, 2026
Copilot AI requested a review from thomhurst February 6, 2026 15:51
@thomhurst thomhurst marked this pull request as ready for review February 6, 2026 16:06
@claude
Copy link
Contributor

claude bot commented Feb 6, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

This PR correctly adds [GeneratedCode] and [ExcludeFromCodeCoverage] attributes to the TestMetadataGenerator output, following the existing pattern used in InfrastructureGenerator and DynamicTestsGenerator. All 86 snapshot tests have been properly updated with .verified.txt files (no .received.txt files committed), which aligns with the snapshot testing requirements in CLAUDE.md.

@claude
Copy link
Contributor

claude bot commented Feb 6, 2026


Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Summary

This PR cleanly adds [GeneratedCode] and [ExcludeFromCodeCoverage] attributes to generated test metadata classes, addressing issue #4688. The change:

Follows existing patterns - Uses the exact same attribute pattern as InfrastructureGenerator.cs and DynamicTestsGenerator.cs
Proper snapshot testing - All 86 .verified.txt files correctly updated, no .received.txt files committed
CLAUDE.md compliant - Meets all critical rules (dual-mode N/A, snapshot testing ✓, performance ✓, AOT compatible ✓)
No bugs - Syntax correct, attributes properly qualified, correct placement

The implementation is straightforward and will improve code coverage reporting by properly marking auto-generated code for exclusion from coverage metrics.


…dCode attributes

The original PR only updated DotNet9_0 variants but missed DotNet8_0,
DotNet10_0, and Net4_7 framework-specific snapshot files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thomhurst thomhurst enabled auto-merge (squash) February 6, 2026 18:29
@thomhurst thomhurst merged commit 65b9b46 into main Feb 6, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the copilot/mark-generated-code-attribute branch February 6, 2026 18:58
thomhurst added a commit that referenced this pull request Feb 6, 2026
…utes

The PR #4690 missed updating the STAThreadTests snapshot files when adding
[ExcludeFromCodeCoverage] and [GeneratedCode] attributes to source generator
output, causing the Windows CI pipeline to fail on snapshot verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
thomhurst added a commit that referenced this pull request Feb 6, 2026
…utes (#4693)

* Initial plan

* Add GeneratedCode and ExcludeFromCodeCoverage attributes to TestMetadataGenerator output

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>

* fix: update remaining framework-specific snapshot files with GeneratedCode attributes

The original PR only updated DotNet9_0 variants but missed DotNet8_0,
DotNet10_0, and Net4_7 framework-specific snapshot files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: Update missed STAThread snapshot files with GeneratedCode attributes

The PR #4690 missed updating the STAThreadTests snapshot files when adding
[ExcludeFromCodeCoverage] and [GeneratedCode] attributes to source generator
output, causing the Windows CI pipeline to fail on snapshot verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Mark TestMetadataGenerator code with generated code attribute

2 participants