From a015ebfba2514bcac46fdbf5699e8e7524e5ae6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 15 Jul 2024 10:23:26 +0200 Subject: [PATCH] Fix timing in simple log --- src/vstest.console/Internal/ConsoleLogger.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 5df4885ebc..7d6ef0278f 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -909,6 +909,20 @@ public MinimalTestResult(TestResult testResult) Outcome = testResult.Outcome; StartTime = testResult.StartTime; EndTime = testResult.EndTime; + + // When the test framework (e.g. xUnit 2.x.x) does not report start or end time + // we assign it to UTC now when constructing the test result. But that does not + // work for our logger, because we take the earliest StartTime and oldest EndTime + // to calculate the duration and this makes the first test to be "missing" from the + // duration. + // + // Instead we subtract the duration to get a more accurate result. We also + // don't compare the times for equality because the times in the TestResult are assigned + // on two different lines so they don't have to be the same. + if (EndTime - StartTime < testResult.Duration) + { + StartTime = EndTime - testResult.Duration; + } } public TestCase TestCase { get; }