feat: test execution metrics collection#4954
Conversation
Code ReviewBug: Asymmetric concurrency counter for dependency-skipped testsThe However, there is a logic bug in how The problem: In TUnit/TUnit.Engine/Scheduling/TestRunner.cs Lines 84 to 92 in b95e529
TUnit/TUnit.Engine/Scheduling/TestRunner.cs Lines 95 to 100 in b95e529 Meanwhile, TUnit/TUnit.Engine/Services/TestMetricsCollector.cs Lines 68 to 72 in b95e529 The consequence: Every dependency-skipped test decrements Suggested fix: The cleanest fix is to add a dedicated // In TestMetricsCollector.cs
public void OnTestSkippedBeforeStart()
{
Interlocked.Increment(ref _totalTests);
Interlocked.Increment(ref _skippedTests);
}And in // Before:
_metricsCollector?.OnTestCompleted(passed: false, skipped: true, duration: null);
// After:
_metricsCollector?.OnTestSkippedBeforeStart();This separates the "test lifecycle" tracking ( |
Add a TestMetricsCollector service that tracks test execution statistics and outputs a summary when enabled via the --metrics command-line flag. Tracks total/pass/fail/skip counts, average duration, peak concurrency, wall-clock time, and memory usage (start/end/delta). Closes #4896
When a test is skipped due to a failed dependency, OnTestCompleted was called without a prior OnTestStarted, causing the concurrent test counter to go below zero. Add a dedicated OnTestSkipped method that only increments the skip counter without touching concurrency.
9eabfd0 to
638c10b
Compare
Closes #4896. Adds --metrics flag with TestMetricsCollector.