Skip to content

[file-diet] Refactor TerminalTestReporter.Summary.cs (715 lines) into focused partial files #10367

Closed

Description

@github-actions

Overview

The file src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Summary.cs has grown to 715 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused partial-class files — consistent with how the rest of TerminalTestReporter is already organized.

Current State

  • File: src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Summary.cs
  • Size: 715 lines
  • Language: C#
Structural Analysis

The file is a partial class on TerminalTestReporter and contains three distinct concerns:

  1. Test-run summary (lines 13–521): AppendTestRunSummary, AppendSlowestTests, AppendSlowestTestLine, AppendFlakyTests, AppendFlakyTestLine, AppendRetrySummaryLines. These methods render the post-run verdict including pass/fail/skip counts, slowest-tests ranking, and retry/flaky-test details.

  2. Discovery summary (lines 234–349): TestDiscovered (two overloads) and AppendTestDiscoverySummary. These methods handle the test-discovery mode output path, which is conceptually separate from execution output.

  3. Coverage summary (lines 523–715): AppendCoverageSummary (public and private overloads), FormatThresholdPercentages, GetCoverageScopeLabel, GetCoverageMetricLabel, GetCoverageThresholdLabel, GetCoverageAggregationLabel, GetCoverageScopeLevelLabel. This block renders code-coverage results and threshold pass/fail results; it is self-contained and already the largest logical section.

Refactoring Strategy

Proposed File Splits

The TerminalTestReporter.Summary.cs file should be split along existing logical boundaries into three focused files:

  1. TerminalTestReporter.Summary.cs (retained, trimmed)

    • Contents: AppendTestRunSummary, AppendSlowestTests, AppendSlowestTestLine, AppendFlakyTests, AppendFlakyTestLine, AppendRetrySummaryLines
    • Responsibility: Render the post-execution run summary (verdict, counts, slowest/flaky tests, retry details)
    • Estimated size: ~340 lines
  2. TerminalTestReporter.Discovery.cs (new file)

    • Contents: TestDiscovered (both overloads), AppendTestDiscoverySummary
    • Responsibility: Handle test-discovery mode output — tracking discovered tests and rendering the discovery summary
    • Estimated size: ~120 lines
  3. TerminalTestReporter.Coverage.cs (new file)

    • Contents: AppendCoverageSummary (public + private), FormatThresholdPercentages, GetCoverageScopeLabel, GetCoverageMetricLabel, GetCoverageThresholdLabel, GetCoverageAggregationLabel, GetCoverageScopeLevelLabel
    • Responsibility: Render code-coverage summary and threshold results
    • Estimated size: ~200 lines

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Public API: internal and public members stay accessible with the same names (partial class guarantees this)
  3. Test After Each Split: Run the unit and acceptance test suites after each incremental file move
  4. One File at a Time: Move the coverage block first (self-contained), then discovery, leaving the trimmed summary last
  5. No new using directives needed: All three new files share the same using set as today

Acceptance Criteria

  • TerminalTestReporter.Summary.cs is split into focused partial files
  • Each new file is under 350 lines
  • All unit tests pass after refactoring (./build.sh -test / .\build.cmd -test)
  • No breaking changes to public or internal API
  • File naming follows the existing TerminalTestReporter.<Concern>.cs convention

Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier focused review, reduced merge conflicts on this high-churn file

🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · sonnet46 52.3 AIC · ⌖ 5.75 AIC · ⊞ 8K · [◷]( · ◷)

  • expires on Aug 2, 2026, 7:19 PM UTC

Activity

  1. added
    type/tech-debt
    type/automation
    on Jul 31, 2026
  2. github-actions commented on Aug 2, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-08-02T19:19:50.547Z.

    Closed by Workflow

  3. added 2 commits that reference this issue on Aug 2, 2026
    c450377
    58192e3
  4. github-actions commented on Aug 3, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-08-02T19:19:50.547Z.

    Closed by Workflow

  5. Evangelink commented on Aug 3, 2026

    @Evangelink
    Member

    Already done — this landed in #10387 (merged acb5bafaa, 2026-08-03 08:19 UTC).

    The issue was auto-closed as expired at 01:09 UTC, before that PR merged, so the Fixes #10367 link had nothing left to close. It was then reopened at 08:26 UTC as part of undoing the bot's expiry closes, which is why it looks outstanding.

    I re-verified against current main rather than taking the PR's word for it:

    Acceptance criteria

    Criterion Result
    Summary.cs split into focused partials ✅ 5 files
    Each new file under 350 lines ✅ max is Coverage.cs at 179
    Unit tests pass ✅ see below
    No public/internal API break ✅ partial-class split, no signature touched
    TerminalTestReporter.<Concern>.cs naming ✅
    TerminalTestReporter.Summary.cs         209
    TerminalTestReporter.Coverage.cs        179
    TerminalTestReporter.TestDiscovery.cs   112
    TerminalTestReporter.FlakyTests.cs       74
    TerminalTestReporter.SlowestTests.cs     70
    

    Behavior preservation — checked mechanically, not by eye. The 606 non-empty class-body lines of the pre-split Summary.cs (acb5bafaa^) and of the five files replacing it are an identical multiset: nothing was added, dropped or edited, only moved.

    Validation on current main

    • Microsoft.Testing.Platform — builds for net8.0 / net9.0 / netstandard2.0, 0 warnings (which is also what proves each file's using set is exactly minimal, since IDE0005 is warning with EnforceCodeStyleInBuild).
    • Microsoft.Testing.Platform.UnitTests — passing on net8.0, net9.0, net462.
    • Microsoft.Testing.Platform.TerminalReporterContract.UnitTests — passing on net8.0, net9.0, confirming the reporter still compiles as a standalone shared-source consumer with no platform reference. TerminalReporterContract.props includes the folder via a *.cs glob, so the four new partials were picked up with no manifest change needed on our side.

    The one genuine follow-up — adding the four new paths to dotnet/sdk's eng/vendored-files.json, which enumerates each partial individually — is tracked separately in #10390 and is a change in that repo, not here.

    Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/automationtype/tech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions