Skip to content

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions