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 and others added 2 commits November 4, 2025 14:10
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
… helper

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
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
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
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
_logger.LogError("Error during test setup", realException);
DateTimeOffset stepEndTime = DateTimeOffset.UtcNow;
TestNode errorNode = CloneTestNode(testNode);
errorNode.Properties.Add(new TimingProperty(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of errors, won't we add the timing property twice? Once here in the catch, and once in the finally from the caller?

@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

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