Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[file-diet] Refactor TestMethodInfo.Execution.cs (574 lines) into focused files

Chiusa
#12,028 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Evangelink ci sta già lavorando.

Dal 20/10/2026.

  • #12040 di @copilot-swe-agent — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend, testing

Direzione di ricerca

Start with src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs and read the complete method bodies, then inspect the neighboring TestMethodInfo.*.cs partials and .github/skills/behavior-preserving-refactor/SKILL.md. Trace consumers, project includes, source links, and the NETFRAMEWORK conditional before moving code. Done means focused files stay under 300 lines where safe, behavior and API contracts are preserved, and affected builds and tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type/automation type/tech-debt
Overview

The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs has grown to 574 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.

Current State
  • File: src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.Execution.cs
  • Size: 574 lines
  • Language: C#
Structural Analysis

This file is already one of six partial class TestMethodInfo files in the Execution folder (alongside .ArgumentResolution.cs, .ExceptionHandling.cs, .Lifecycle.cs, .TestContext.cs, and .cs), so the project already follows a per-concern partial-class convention — this file itself has simply outgrown that convention and can be split further along the same lines.

From the bounded sample (first 100 lines + a member-signature grep), the file contains:

  • GetTestTimeout() — resolves the effective TimeoutAttribute/default timeout for a test method.
  • ThrowMultipleAttributesException / ThrowMultipleClassAttributesException — small [DoesNotReturn] helpers that raise TypeInspectionException for duplicate attribute usage.
  • ExecuteInternalAsync(...) (lines ~77–336) — the large core method that orchestrates global/local test initialization, test invocation, and global/local cleanup.
  • DefaultTestClassInstanceLease (lines ~336–363) — a private nested sealed class implementing ITestClassInstanceLease.
  • ExecuteInternalWithTimeoutAsync(...) (lines ~363–526) — the timeout-wrapping variant of execution.
  • TestInvocationState (lines ~526–570) — a private nested class tracking activation/cleanup state (PublishActivation, CompleteTestContextSetup).
  • TestInvocationCleanupSnapshot (line ~570+) — a private nested readonly record struct capturing cleanup snapshot data.
Refactoring Strategy
Proposed File Splits

Based on the bounded structural sample, investigate these proposed splits as provisional — the sample used for this issue did not read the full method bodies or verify consumer/test coupling, so their safety must be confirmed during implementation preflight before moving any code:

  1. TestMethodInfo.Execution.cs (retained, trimmed)

    • Contents: GetTestTimeout(), ThrowMultipleAttributesException, ThrowMultipleClassAttributesException, and the primary ExecuteInternalAsync(...) entry point.
    • Responsibility: Core non-timeout test execution orchestration and small attribute-validation helpers.
  2. TestMethodInfo.Execution.Timeout.cs

    • Contents: ExecuteInternalWithTimeoutAsync(...) and the TestInvocationState nested class it uses to track invocation/cleanup state.
    • Responsibility: Timeout-bounded test execution path, isolated from the non-timeout path.
  3. TestMethodInfo.Execution.Types.cs (if needed)

    • Contents: DefaultTestClassInstanceLease and TestInvocationCleanupSnapshot nested types.
    • Responsibility: Small supporting types (lease/snapshot) shared by both execution paths, separated from the executable logic.
Implementation Guidelines
  1. Establish Equivalence: Follow .github/skills/behavior-preserving-refactor/SKILL.md. Before editing, read the complete affected bodies, inventory baseline behavior and relevant tests, and identify distinguishing cases.
  2. Preserve Selection and Evaluation: Keep iteration order, short-circuit evaluation, exact type selection, first/last-match semantics, defaults, exceptions, and side effects. Cover reachable duplicate and malformed inputs; similar-looking helpers are not automatically interchangeable.
  3. Trace All Consumers: Check partial declarations, source-linked consumers, owning/consuming project includes, target-framework guards (e.g. the #if NETFRAMEWORK block at the top of the file), and tracked public/internal API surfaces. Keep names, accessibility, attributes, and native interop contracts unchanged.
  4. Move Before Modernizing: Move bodies unchanged first, one coherent responsibility at a time. Preserve allocation and performance behavior on hot paths; do not mix adjacent modernization or bug fixes into the split.
  5. Use Focused Checks: Run the smallest affected project/TFM builds and relevant tests before and after each coherent split. Add distinguishing equivalence cases where coverage is missing; a pure file move does not require the full solution. Report exact checks and outcomes, including unavailable checks.
  6. Surface Constraints: Measure resulting line counts. If a safe structural split cannot meet the size goal without changing semantics, report the remaining size and blocker rather than forcing behavior changes.
Acceptance Criteria
  • Original file is split into focused modules (following the existing TestMethodInfo.*.cs partial-class convention)
  • Each new file is under 300 lines, or a concrete behavior-preservation blocker and remaining size are reported
  • Baseline semantics, including reachable duplicate/malformed cases and evaluation order, are preserved by focused equivalence checks
  • Relevant builds and tests pass for affected consumers/TFMs (including the NETFRAMEWORK-conditional code path); exact checks and any validation gaps are reported
  • Public and tracked internal API contracts, attributes, and conditional compilation are preserved
  • Project includes, source links, and package layout still include the moved code for every affected consumer

Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts

🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · copilot · auto · 41 AIC · ⌖ 10.4 AIC · ⊞ 12.9K · [◷]( · ◷)

  • expires on Oct 21, 2026, 7:02 PM UTC
Lingua principale
C#
Stelle
1.1k
Fork
312
Merge medio
8h 25m
PR unite (30g)
443

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/testfx

Tutte le issue di microsoft/testfx

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.