Skip to content

Refactor TestNodeProperties.cs (1295 lines) into focused files #7939

Description

@Evangelink

Overview

The file src/Platform/Microsoft.Testing.Platform/Messages/TestNodeProperties.cs has grown to 1295 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.

Current State

  • File: src/Platform/Microsoft.Testing.Platform/Messages/TestNodeProperties.cs
  • Size: 1295 lines
  • Language: C#
Structural Analysis

The file defines many independent types all sharing the same namespace Microsoft.Testing.Platform.Extensions.Messages. They fall into distinct logical groups:

Group Types
Base interface IProperty
State properties TestNodeStateProperty (abstract base), DiscoveredTestNodeStateProperty, InProgressTestNodeStateProperty, PassedTestNodeStateProperty, SkippedTestNodeStateProperty, FailedTestNodeStateProperty, ErrorTestNodeStateProperty, TimeoutTestNodeStateProperty, CancelledTestNodeStateProperty
Timing properties TimingInfo, StepTimingInfo, TimingProperty
Location properties LinePosition, LinePositionSpan, FileLocationProperty (abstract), TestFileLocationProperty
Identity/metadata TestMethodIdentifierProperty, TestMetadataProperty
Output/artifact StandardOutputProperty, StandardErrorProperty, FileArtifactProperty
Internal SerializableKeyValuePairStringProperty

Refactoring Strategy

Proposed File Splits

Based on the file's structure, split it into the following focused files inside src/Platform/Microsoft.Testing.Platform/Messages/:

  1. IProperty.cs

    • Contents: IProperty interface
    • Responsibility: Base contract for all test node properties
  2. TestNodeStateProperties.cs

    • Contents: TestNodeStateProperty, DiscoveredTestNodeStateProperty, InProgressTestNodeStateProperty, PassedTestNodeStateProperty, SkippedTestNodeStateProperty, FailedTestNodeStateProperty, ErrorTestNodeStateProperty, TimeoutTestNodeStateProperty, CancelledTestNodeStateProperty
    • Responsibility: All test execution state properties (pass/fail/skip/timeout/etc.)
  3. TimingProperties.cs

    • Contents: TimingInfo, StepTimingInfo, TimingProperty
    • Responsibility: Elapsed-time and per-step timing data attached to test nodes
  4. FileLocationProperties.cs

    • Contents: LinePosition, LinePositionSpan, FileLocationProperty, TestFileLocationProperty
    • Responsibility: Source file location metadata for test nodes
  5. TestMethodIdentifierProperty.cs

    • Contents: TestMethodIdentifierProperty
    • Responsibility: Strongly-typed identity of the test method (assembly, namespace, type, method, parameters)
  6. TestMetadataProperty.cs

    • Contents: TestMetadataProperty
    • Responsibility: Arbitrary key/value metadata attached to a test node
  7. OutputProperties.cs

    • Contents: StandardOutputProperty, StandardErrorProperty
    • Responsibility: Captured stdout/stderr output produced during a test run
  8. FileArtifactProperty.cs

    • Contents: FileArtifactProperty
    • Responsibility: File artifacts (attachments) produced by a test
  9. SerializableKeyValuePairStringProperty.cs (internal)

    • Contents: SerializableKeyValuePairStringProperty
    • Responsibility: Internal serialization helper property

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Public API: Keep all public symbols in the same namespace (Microsoft.Testing.Platform.Extensions.Messages) — no namespace changes needed
  3. PublicAPI.Unshipped.txt: No changes needed as this is pure restructuring of existing public API
  4. Test After Each Split: Run the test suite (./build.sh) after each incremental file move
  5. One File at a Time: Split one logical group at a time to make review easier
  6. Check PublicAPI.Shipped.txt: Confirm the API surface is unchanged — no entries should be added or removed

Acceptance Criteria

  • TestNodeProperties.cs is replaced by the focused files listed above
  • Each new file is under 300 lines
  • All tests pass after refactoring
  • No breaking changes to public API
  • PublicAPI.Shipped.txt / PublicAPI.Unshipped.txt are unchanged

Priority: Medium
Effort: Small (purely mechanical file splits — no logic changes required)
Expected Impact: Improved code navigability, easier per-type Git history, reduced merge conflicts on this file

Generated by Daily File Diet · ● 234.4K ·

Metadata

Metadata

Labels

type/tech-debtCode health, refactoring, simplification.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions