Overview
The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.cs has grown to 1113 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.cs
- Size: 1113 lines
- Language: C#
Structural Analysis
The file contains a single TestMethodInfo class that has accumulated several distinct responsibilities:
| Lines |
Concern |
| ~23–168 |
Core class definition, properties, InvokeAsync entry point |
| ~169–329 |
Argument resolution (ResolveArguments, SetArguments) |
| ~250–329 |
Timeout resolution (GetTestTimeout, ThrowMultipleAttributesException) |
| ~330–521 |
Main test execution loop (ExecuteInternalAsync) |
| ~522–597 |
Exception handling (HandleMethodException) |
| ~598–782 |
TestCleanup lifecycle (RunTestCleanupMethodAsync, HasCleanupsToInvoke) |
| ~705–857 |
TestInitialize lifecycle (RunTestInitializeMethodAsync, InvokeInitializeMethodAsync, InvokeGlobalInitializeMethodAsync) |
| ~857–958 |
Global cleanup invocation (InvokeGlobalCleanupMethodAsync, CaptureExecutionContextAfterFixtureIfNeeded) |
| ~959–1005 |
TestContext setup (SetTestContext) |
| ~1006–1113 |
Timeout-aware execution (ExecuteInternalWithTimeoutAsync) |
Refactoring Strategy
Since TestMethodInfo is a single class (not multiple classes) and C# supports partial class, the most idiomatic approach for this codebase is to split the implementation into partial class files, each focusing on a specific aspect of test method execution.
Proposed File Splits
-
TestMethodInfo.cs (keep, trimmed)
- Contents: Class declaration, fields, properties, constructor, public
InvokeAsync entry point
- Responsibility: Core identity and public API surface (~150 lines)
-
TestMethodInfo.ArgumentResolution.cs (new partial class)
- Contents:
SetArguments, ResolveArguments
- Responsibility: Mapping data-driven test arguments to method parameters (~160 lines)
-
TestMethodInfo.Execution.cs (new partial class)
- Contents:
ExecuteInternalAsync, ExecuteInternalWithTimeoutAsync, GetTestTimeout, ThrowMultipleAttributesException
- Responsibility: Core test body execution, timeout management (~300 lines)
-
TestMethodInfo.ExceptionHandling.cs (new partial class)
- Contents:
HandleMethodException
- Responsibility: Mapping raw exceptions to
TestFailedException with proper messages (~75 lines)
-
TestMethodInfo.Lifecycle.cs (new partial class)
- Contents:
RunTestInitializeMethodAsync, InvokeInitializeMethodAsync, InvokeGlobalInitializeMethodAsync, RunTestCleanupMethodAsync, InvokeCleanupMethodAsync, InvokeGlobalCleanupMethodAsync, HasCleanupsToInvoke, CaptureExecutionContextAfterFixtureIfNeeded
- Responsibility: TestInitialize / TestCleanup fixture invocation (~430 lines)
-
TestMethodInfo.TestContext.cs (new partial class)
- Contents:
SetTestContext
- Responsibility: Wiring
ITestContext onto the class instance before test execution (~50 lines)
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Public API: Keep exported/public symbols accessible with the same names
- Use
partial class: C# partial classes avoid any need to change access modifiers or visibility
- Test After Each Split: Run the test suite after each incremental file move
- One File at a Time: Split one partial at a time to make review easier
Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier per-concern testing, reduced merge conflicts on busy test execution code
Generated by Daily File Diet · ● 267.4K · ◷
Overview
The file
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.cshas grown to 1113 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.csStructural Analysis
The file contains a single
TestMethodInfoclass that has accumulated several distinct responsibilities:InvokeAsyncentry pointResolveArguments,SetArguments)GetTestTimeout,ThrowMultipleAttributesException)ExecuteInternalAsync)HandleMethodException)RunTestCleanupMethodAsync,HasCleanupsToInvoke)RunTestInitializeMethodAsync,InvokeInitializeMethodAsync,InvokeGlobalInitializeMethodAsync)InvokeGlobalCleanupMethodAsync,CaptureExecutionContextAfterFixtureIfNeeded)SetTestContext)ExecuteInternalWithTimeoutAsync)Refactoring Strategy
Since
TestMethodInfois a single class (not multiple classes) and C# supportspartial class, the most idiomatic approach for this codebase is to split the implementation into partial class files, each focusing on a specific aspect of test method execution.Proposed File Splits
TestMethodInfo.cs(keep, trimmed)InvokeAsyncentry pointTestMethodInfo.ArgumentResolution.cs(new partial class)SetArguments,ResolveArgumentsTestMethodInfo.Execution.cs(new partial class)ExecuteInternalAsync,ExecuteInternalWithTimeoutAsync,GetTestTimeout,ThrowMultipleAttributesExceptionTestMethodInfo.ExceptionHandling.cs(new partial class)HandleMethodExceptionTestFailedExceptionwith proper messages (~75 lines)TestMethodInfo.Lifecycle.cs(new partial class)RunTestInitializeMethodAsync,InvokeInitializeMethodAsync,InvokeGlobalInitializeMethodAsync,RunTestCleanupMethodAsync,InvokeCleanupMethodAsync,InvokeGlobalCleanupMethodAsync,HasCleanupsToInvoke,CaptureExecutionContextAfterFixtureIfNeededTestMethodInfo.TestContext.cs(new partial class)SetTestContextITestContextonto the class instance before test execution (~50 lines)Implementation Guidelines
partial class: C# partial classes avoid any need to change access modifiers or visibilityAcceptance Criteria
partial classfiles (one per concern)Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier per-concern testing, reduced merge conflicts on busy test execution code