diff --git a/GitHubActionsTestLogger/TestLoggerContext.cs b/GitHubActionsTestLogger/TestLoggerContext.cs index 64100a6..6f1ec4a 100644 --- a/GitHubActionsTestLogger/TestLoggerContext.cs +++ b/GitHubActionsTestLogger/TestLoggerContext.cs @@ -101,7 +101,22 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args) _testRunCriteria?.TryGetTargetFramework() ?? "Unknown Target Framework", - TestRunResult = new TestRunResult(_testResults, args.ElapsedTimeInRunningTests) + TestRunStatistics = new TestRunStatistics( + (int?)args.TestRunStatistics?[TestOutcome.Passed] ?? + _testResults.Count(r => r.Outcome == TestOutcome.Passed), + + (int?)args.TestRunStatistics?[TestOutcome.Failed] ?? + _testResults.Count(r => r.Outcome == TestOutcome.Failed), + + (int?)args.TestRunStatistics?[TestOutcome.Skipped] ?? + _testResults.Count(r => r.Outcome == TestOutcome.Skipped), + + (int?)args.TestRunStatistics?.ExecutedTests ?? _testResults.Count, + + args.ElapsedTimeInRunningTests + ), + + TestResults = _testResults }; _github.CreateSummary(template.Render()); diff --git a/GitHubActionsTestLogger/TestRunResult.cs b/GitHubActionsTestLogger/TestRunResult.cs deleted file mode 100644 index 311ebf2..0000000 --- a/GitHubActionsTestLogger/TestRunResult.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; - -namespace GitHubActionsTestLogger; - -internal record TestRunResult(IReadOnlyList TestResults, TimeSpan OverallDuration) -{ - public int PassedTestCount => TestResults.Count(r => r.Outcome == TestOutcome.Passed); - - public int FailedTestCount => TestResults.Count(r => r.Outcome == TestOutcome.Failed); - - public int SkippedTestCount => TestResults.Count(r => r.Outcome == TestOutcome.Skipped); - - public int TotalTestCount => TestResults.Count; - - public TestOutcome OverallOutcome - { - get - { - if (FailedTestCount > 0) - return TestOutcome.Failed; - - if (PassedTestCount > 0) - return TestOutcome.Passed; - - if (SkippedTestCount > 0) - return TestOutcome.Skipped; - - return TestOutcome.None; - } - } -} \ No newline at end of file diff --git a/GitHubActionsTestLogger/TestRunStatistics.cs b/GitHubActionsTestLogger/TestRunStatistics.cs new file mode 100644 index 0000000..04a29b8 --- /dev/null +++ b/GitHubActionsTestLogger/TestRunStatistics.cs @@ -0,0 +1,29 @@ +using System; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; + +namespace GitHubActionsTestLogger; + +internal record TestRunStatistics( + int PassedTestCount, + int FailedTestCount, + int SkippedTestCount, + int TotalTestCount, + TimeSpan OverallDuration) +{ + public TestOutcome OverallOutcome + { + get + { + if (FailedTestCount > 0) + return TestOutcome.Failed; + + if (PassedTestCount > 0) + return TestOutcome.Passed; + + if (SkippedTestCount > 0) + return TestOutcome.Skipped; + + return TestOutcome.None; + } + } +} \ No newline at end of file diff --git a/GitHubActionsTestLogger/TestSummaryTemplate.cshtml b/GitHubActionsTestLogger/TestSummaryTemplate.cshtml index aba08d6..ae967a3 100644 --- a/GitHubActionsTestLogger/TestSummaryTemplate.cshtml +++ b/GitHubActionsTestLogger/TestSummaryTemplate.cshtml @@ -14,12 +14,14 @@ public required string TargetFramework { get; init; } - public required TestRunResult TestRunResult { get; init; } + public required TestRunStatistics TestRunStatistics { get; init; } + + public required IReadOnlyList TestResults { get; init; } }
@{ - var overallOutcomeEmoji = TestRunResult.OverallOutcome switch + var overallOutcomeEmoji = TestRunStatistics.OverallOutcome switch { TestOutcome.Passed => "🟢", TestOutcome.Failed => "🔴", @@ -42,32 +44,31 @@ ⧗  Elapsed - @(TestRunResult.PassedTestCount > 0 - ? TestRunResult.PassedTestCount.ToString() + @(TestRunStatistics.PassedTestCount > 0 + ? TestRunStatistics.PassedTestCount.ToString() : "—") - @(TestRunResult.FailedTestCount > 0 - ? TestRunResult.FailedTestCount.ToString() + @(TestRunStatistics.FailedTestCount > 0 + ? TestRunStatistics.FailedTestCount.ToString() : "—") - @(TestRunResult.SkippedTestCount > 0 - ? TestRunResult.SkippedTestCount.ToString() + @(TestRunStatistics.SkippedTestCount > 0 + ? TestRunStatistics.SkippedTestCount.ToString() : "—") - @TestRunResult.TotalTestCount + @TestRunStatistics.TotalTestCount - @TestRunResult.OverallDuration.ToHumanString() + @TestRunStatistics.OverallDuration.ToHumanString() @{ - var testResultGroups = TestRunResult - .TestResults + var testResultGroups = TestResults .Where(r => r.Outcome == TestOutcome.Failed || r.Outcome == TestOutcome.Passed && Options.SummaryIncludePassedTests ||