From 5f0ee02f98bba87ca79078df6e843350ee3e30b1 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 24 Feb 2026 10:52:51 +0100 Subject: [PATCH 1/2] [tests] Fix Windows test summary always reporting 'All tests passed' Fix a copy-paste bug in create-windows-html-report.cs where both the success and failure branches wrote '# :tada: All N tests passed :tada:'. The failure branch now generates a proper summary with
/ tags listing failed tests, matching the format TestResults.psm1 expects. Also fix TestResults.psm1 to emit
before (correct HTML nesting order), and avoid including misleading success-format file content in the failure section when the result file has no failure details. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../create-windows-html-report.cs | 35 +++++++++++++++++-- .../automation/scripts/TestResults.Tests.ps1 | 6 ++-- .../automation/scripts/TestResults.psm1 | 18 ++++++---- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/scripts/create-windows-html-report/create-windows-html-report.cs b/scripts/create-windows-html-report/create-windows-html-report.cs index f17faa30308c..e23efdcee269 100644 --- a/scripts/create-windows-html-report/create-windows-html-report.cs +++ b/scripts/create-windows-html-report/create-windows-html-report.cs @@ -85,6 +85,10 @@ public static int Main (string [] args) var indexContents = new StringBuilder (); var summaryContents = new StringBuilder (); + var allFailedTests = new List<(string TrxName, TrxTestResult Test)> (); + var failedTrxNames = new List (); + var passedTrxCount = 0; + var failedTrxCount = 0; indexContents.AppendLine ($""); indexContents.AppendLine ($""); @@ -123,9 +127,12 @@ public static int Main (string [] args) var name = trx.Name; var path = trx.TestResults; var messageLines = new List (); + var trxSucceeded = true; - if (TrxParser.TryParseTrxFile (path, out var failedTests, out var outcome, out allTestsSucceeded, out var ex)) { + if (TrxParser.TryParseTrxFile (path, out var failedTests, out var outcome, out trxSucceeded, out var ex)) { if (failedTests?.Any () == true) { + foreach (var ft in failedTests) + allFailedTests.Add ((name, ft)); messageLines.Add ("
    "); foreach (var ft in failedTests) { var testName = ft.Name; @@ -152,7 +159,15 @@ public static int Main (string [] args) outcome = "Failed to parse test results"; if (ex is not null) messageLines.Add ($"
    {FormatHtml (ex.ToString ())}
    "); + trxSucceeded = false; + } + + if (!trxSucceeded) { allTestsSucceeded = false; + failedTrxNames.Add (name); + failedTrxCount++; + } else { + passedTrxCount++; } try { @@ -194,7 +209,23 @@ public static int Main (string [] args) if (allTestsSucceeded) { summaryContents.AppendLine ($"# :tada: All {trxFiles.Length} tests passed :tada:"); } else { - summaryContents.AppendLine ($"# :tada: All {trxFiles.Length} tests passed :tada:"); + summaryContents.AppendLine ("# Test results"); + summaryContents.AppendLine ("
    "); + summaryContents.AppendLine ($"{failedTrxCount} tests failed, {passedTrxCount} tests passed."); + summaryContents.AppendLine (); + summaryContents.AppendLine ("## Failed tests"); + summaryContents.AppendLine (); + if (allFailedTests.Any ()) { + foreach (var (trxName, test) in allFailedTests) { + var msg = string.IsNullOrEmpty (test.Message) ? "" : $": {test.Message.Split ('\n') [0]}"; + summaryContents.AppendLine ($" * {trxName}/{test.Name}: {test.Outcome}{msg}"); + } + } else { + foreach (var trxName in failedTrxNames) { + summaryContents.AppendLine ($" * {trxName}: Failed"); + } + } + summaryContents.AppendLine ("
    "); } Directory.CreateDirectory (outputDirectory); diff --git a/tools/devops/automation/scripts/TestResults.Tests.ps1 b/tools/devops/automation/scripts/TestResults.Tests.ps1 index 6178bd86a398..1a27744780c7 100644 --- a/tools/devops/automation/scripts/TestResults.Tests.ps1 +++ b/tools/devops/automation/scripts/TestResults.Tests.ps1 @@ -908,8 +908,8 @@ Describe "TestResults tests" { ### :x: dotnettests tests (MacCatalyst) -5 tests failed, 6 tests passed.
    +5 tests failed, 6 tests passed.
    @@ -1002,9 +1002,9 @@ Describe "TestResults tests" { ### :x: dotnettests tests (MacCatalyst) -1 tests failed, 0 tests passed.
    -# :tada: All 5 tests passed :tada: +1 tests failed, 0 tests passed. +Test results reported success, but the tests job failed.
    [Html Report (VSDrops)](vsdropsIndex/testStagedotnettests_maccatalyst-1/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-testStagedotnettests_maccatalyst-1&api-version=6.0&`$format=zip) diff --git a/tools/devops/automation/scripts/TestResults.psm1 b/tools/devops/automation/scripts/TestResults.psm1 index 1e3693b374d2..97c23e6031be 100644 --- a/tools/devops/automation/scripts/TestResults.psm1 +++ b/tools/devops/automation/scripts/TestResults.psm1 @@ -447,17 +447,21 @@ class ParallelTestsResults { $resultLines = @("Test has no summary file.") } - if ($addSummary) { - $stringBuilder.AppendLine("$($result.Failed) tests failed, $($result.Passed) tests passed.") - } if ($addDetails) { $stringBuilder.AppendLine("
    ") } - if ($startLine -eq -1) { - $startLine = 0 + if ($addSummary) { + $stringBuilder.AppendLine("$($result.Failed) tests failed, $($result.Passed) tests passed.") } - for ($i = $startLine; $i -lt $resultLines.Length; $i++) { - $stringBuilder.AppendLine($resultLines[$i]) + if ($startLine -eq -1) { + # No
    , , or ## Failed tests found in the file. + # The file likely has the success format (e.g. "# :tada: All N tests passed :tada:"), + # which would be misleading in a failure section. Show a job failure message instead. + $stringBuilder.AppendLine("Test results reported success, but the tests job failed.") + } else { + for ($i = $startLine; $i -lt $resultLines.Length; $i++) { + $stringBuilder.AppendLine($resultLines[$i]) + } } if ($addDetails) { $stringBuilder.AppendLine("
    ") From 9f585a6ef854463964dbef77ca410e3c364266ad Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 24 Feb 2026 20:21:36 +0100 Subject: [PATCH 2/2] Fix TrxTestResult type reference to TrxParser.TrxTestResult Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../create-windows-html-report/create-windows-html-report.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-windows-html-report/create-windows-html-report.cs b/scripts/create-windows-html-report/create-windows-html-report.cs index e23efdcee269..34e734a1b65b 100644 --- a/scripts/create-windows-html-report/create-windows-html-report.cs +++ b/scripts/create-windows-html-report/create-windows-html-report.cs @@ -85,7 +85,7 @@ public static int Main (string [] args) var indexContents = new StringBuilder (); var summaryContents = new StringBuilder (); - var allFailedTests = new List<(string TrxName, TrxTestResult Test)> (); + var allFailedTests = new List<(string TrxName, TrxParser.TrxTestResult Test)> (); var failedTrxNames = new List (); var passedTrxCount = 0; var failedTrxCount = 0;