Skip to content

Commit

Permalink
Revert to previous approach with TestRunStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 19, 2023
1 parent 3899451 commit c8a4000
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 47 deletions.
17 changes: 16 additions & 1 deletion GitHubActionsTestLogger/TestLoggerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
34 changes: 0 additions & 34 deletions GitHubActionsTestLogger/TestRunResult.cs

This file was deleted.

29 changes: 29 additions & 0 deletions GitHubActionsTestLogger/TestRunStatistics.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
25 changes: 13 additions & 12 deletions GitHubActionsTestLogger/TestSummaryTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestResult> TestResults { get; init; }
}

<details>
@{
var overallOutcomeEmoji = TestRunResult.OverallOutcome switch
var overallOutcomeEmoji = TestRunStatistics.OverallOutcome switch
{
TestOutcome.Passed => "🟢",
TestOutcome.Failed => "🔴",
Expand All @@ -42,32 +44,31 @@
<th width="99999">⧗&nbsp;&nbsp;Elapsed</th>
<tr>
<td align="center">
@(TestRunResult.PassedTestCount > 0
? TestRunResult.PassedTestCount.ToString()
@(TestRunStatistics.PassedTestCount > 0
? TestRunStatistics.PassedTestCount.ToString()
: "")
</td>
<td align="center">
@(TestRunResult.FailedTestCount > 0
? TestRunResult.FailedTestCount.ToString()
@(TestRunStatistics.FailedTestCount > 0
? TestRunStatistics.FailedTestCount.ToString()
: "")
</td>
<td align="center">
@(TestRunResult.SkippedTestCount > 0
? TestRunResult.SkippedTestCount.ToString()
@(TestRunStatistics.SkippedTestCount > 0
? TestRunStatistics.SkippedTestCount.ToString()
: "")
</td>
<td align="center">
@TestRunResult.TotalTestCount
@TestRunStatistics.TotalTestCount
</td>
<td align="center">
@TestRunResult.OverallDuration.ToHumanString()
@TestRunStatistics.OverallDuration.ToHumanString()
</td>
</tr>
</table>

@{
var testResultGroups = TestRunResult
.TestResults
var testResultGroups = TestResults
.Where(r =>
r.Outcome == TestOutcome.Failed ||
r.Outcome == TestOutcome.Passed && Options.SummaryIncludePassedTests ||
Expand Down

0 comments on commit c8a4000

Please sign in to comment.