From bc68864792fea1c0728495416735634cd2b6fda7 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:53:11 +0000 Subject: [PATCH] Exception Details in GitHub Summary --- TUnit.Engine/Reporters/GitHubReporter.cs | 70 ++++++++++++++++++------ 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/TUnit.Engine/Reporters/GitHubReporter.cs b/TUnit.Engine/Reporters/GitHubReporter.cs index 049e501719..2704485240 100644 --- a/TUnit.Engine/Reporters/GitHubReporter.cs +++ b/TUnit.Engine/Reporters/GitHubReporter.cs @@ -98,32 +98,29 @@ public Task AfterRunAsync(int exitCode, CancellationToken cancellation) stringBuilder.AppendLine(); stringBuilder.AppendLine("## Information"); stringBuilder.AppendLine(); - stringBuilder.AppendLine("| Test | Status | Start | End | Duration |"); - stringBuilder.AppendLine("| _ | _ | _ | _ | _ |"); + stringBuilder.AppendLine("| Test | Status | Details | Duration |"); + stringBuilder.AppendLine("| _ | _ | _ | _ |"); foreach (var testNodeUpdateMessage in last.Values) { var name = testNodeUpdateMessage.TestNode.DisplayName; - - var status = GetStatus(testNodeUpdateMessage); - if (status == "Passed") + var stateProperty = testNodeUpdateMessage.Properties.OfType().FirstOrDefault(); + + if (stateProperty is PassedTestNodeStateProperty) { continue; } - - var timingProperty = testNodeUpdateMessage.Properties.AsEnumerable().OfType().FirstOrDefault(); - var start = timingProperty - ?.GlobalTiming.StartTime; + var status = GetStatus(stateProperty); + + var details = GetDetails(stateProperty, testNodeUpdateMessage.Properties); - var end = timingProperty - ?.GlobalTiming.StartTime; + var timingProperty = testNodeUpdateMessage.Properties.AsEnumerable().OfType().FirstOrDefault(); - var duration = timingProperty - ?.GlobalTiming.Duration; + var duration = timingProperty?.GlobalTiming.Duration; - stringBuilder.AppendLine($"| {name} | {status} | {start} | {end} | {duration} |"); + stringBuilder.AppendLine($"| {name} | {status} | {details} | {duration} |"); } #if NET @@ -134,10 +131,51 @@ public Task AfterRunAsync(int exitCode, CancellationToken cancellation) #endif } - private static string GetStatus(TestNodeUpdateMessage testNodeUpdateMessage) + private string GetDetails(TestNodeStateProperty? stateProperty, PropertyBag properties) { - var stateProperty = testNodeUpdateMessage.Properties.OfType().FirstOrDefault(); + if (stateProperty is FailedTestNodeStateProperty + or ErrorTestNodeStateProperty + or TimeoutTestNodeStateProperty + or CancelledTestNodeStateProperty) + { + return GetError(stateProperty)!; + } + + if (stateProperty is SkippedTestNodeStateProperty skippedTestNodeStateProperty) + { + return skippedTestNodeStateProperty.Explanation ?? "Skipped (No reason provided)"; + } + + if (stateProperty is InProgressTestNodeStateProperty) + { + var timingProperty = properties.AsEnumerable().OfType().FirstOrDefault(); + var start = timingProperty?.GlobalTiming.StartTime; + var end = timingProperty?.GlobalTiming.EndTime; + + return $"Start: {start} | End: {end}"; + } + + return "Unknown Test State"; + } + + private string? GetError(TestNodeStateProperty? stateProperty) + { + return stateProperty switch + { + ErrorTestNodeStateProperty errorTestNodeStateProperty => errorTestNodeStateProperty.Exception?.ToString() ?? + errorTestNodeStateProperty.Explanation, + FailedTestNodeStateProperty failedTestNodeStateProperty => + failedTestNodeStateProperty.Exception?.ToString() ?? failedTestNodeStateProperty.Explanation, + TimeoutTestNodeStateProperty timeoutTestNodeStateProperty => timeoutTestNodeStateProperty.Exception + ?.ToString() ?? timeoutTestNodeStateProperty.Explanation, + CancelledTestNodeStateProperty cancelledTestNodeStateProperty => cancelledTestNodeStateProperty.Exception?.ToString() ?? cancelledTestNodeStateProperty.Explanation, + _ => null + }; + } + + private static string GetStatus(TestNodeStateProperty? stateProperty) + { return stateProperty switch { CancelledTestNodeStateProperty => "Cancelled",