Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

The internal test framework (TestFramework.ForTestingMSTest) was not reporting timing information for test executions.

Changes

  • Capture timing in ExecuteTestNodeRunAsync: Record start time before test execution, add TimingProperty in finally block to ensure timing is always reported
  • Add step timing for test phases: Track timing separately for each phase (initialization, test execution, cleanup) using StepTimingInfo
  • Return step timing from helper methods: Modified TryRunSetupMethodAsync, RunTestMethodAsync, and RunTestTeardownAsync to return tuples containing both the result and step timing
  • Extract CreateTimingProperty helper: Centralize timing calculation to reduce duplication

Implementation

DateTimeOffset startTime = DateTimeOffset.UtcNow;
List<StepTimingInfo> stepTimings = new();

try
{
    // Collect step timing for each phase
    (object? testClassInstance, StepTimingInfo? setupTiming) = await TryRunSetupMethodAsync(...);
    if (setupTiming is not null)
    {
        stepTimings.Add(setupTiming);
    }
    // ... similar for test and cleanup phases
}
finally
{
    testNode.Properties.Add(CreateTimingProperty(startTime, stepTimings));
}

private static TimingProperty CreateTimingProperty(DateTimeOffset startTime, List<StepTimingInfo> stepTimings)
{
    DateTimeOffset endTime = DateTimeOffset.UtcNow;
    TimeSpan duration = endTime - startTime;
    return new TimingProperty(new TimingInfo(startTime, endTime, duration), [.. stepTimings]);
}

All test nodes (passed and error states) now include timing information with detailed breakdown by phase:

  • init: Test initialization (constructor)
  • test: Test method execution
  • cleanup: Test cleanup (dispose)

This provides both global timing and per-phase timing for performance analysis and test reporting.

Original prompt

This section details on the original issue you should resolve

<issue_title>Internal test framework should add TimingProperty to test nodes</issue_title>
<issue_description>We have a custom simple test framework that we use to test MSTest. We should add TimingProperty to the test node there.</issue_description>

<agent_instructions>Update file test/Utilities/TestFramework.ForTestingMSTest/TestFrameworkEngine.cs </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add TimingProperty to test nodes in custom framework Add TimingProperty to internal test framework test nodes Nov 4, 2025
Copilot AI requested a review from Evangelink November 4, 2025 14:17
Copilot finished work on behalf of Evangelink November 4, 2025 14:17
Copilot AI changed the title Add TimingProperty to internal test framework test nodes Add TimingProperty with step timing to internal test framework test nodes Nov 4, 2025
Copilot AI requested a review from Evangelink November 4, 2025 15:57
Copilot finished work on behalf of Evangelink November 4, 2025 15:57
@Evangelink Evangelink marked this pull request as ready for review November 4, 2025 19:15
@Evangelink Evangelink enabled auto-merge (squash) November 4, 2025 19:17
@Romfos
Copy link

Romfos commented Nov 19, 2025

Have you seen problem with Visual Studio with test class time calculation?

image

and look like VS summarize time for tests execution for class

@Evangelink
Copy link
Member

Hi @Romfos,

Thanks for raising your feedback. I'd be ideal to create a custom issues but in this case this is a known issue of Test Explorer (owned by a different team), it'd be amazing if you could report it using the VS feedback button.

@Evangelink Evangelink merged commit b871129 into main Nov 24, 2025
8 checks passed
@Evangelink Evangelink deleted the copilot/add-timingproperty-to-test-nodes branch November 24, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal test framework should add TimingProperty to test nodes

4 participants