Skip to content

Commit f3ad827

Browse files
authored
Add support for not reporting empty test assemblies (#26)
1 parent bf14ebd commit f3ad827

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed

GitHubActionsTestLogger.Tests/SummarySpecs.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,46 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
184184

185185
testOutput.WriteLine(output);
186186
}
187+
188+
[Fact]
189+
public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_assemblies()
190+
{
191+
// Arrange
192+
using var summaryWriter = new StringWriter();
193+
194+
var context = new TestLoggerContext(
195+
new GitHubWorkflow(TextWriter.Null, summaryWriter),
196+
TestLoggerOptions.Default
197+
);
198+
199+
// Act
200+
context.SimulateTestRun();
201+
202+
// Assert
203+
var output = summaryWriter.ToString().Trim();
204+
output.Should().Contain("⚪️ FakeTests");
205+
206+
testOutput.WriteLine(output);
207+
}
208+
209+
[Fact]
210+
public void I_can_use_the_logger_to_produce_no_summary_for_empty_test_assemblies_using_options()
211+
{
212+
// Arrange
213+
using var summaryWriter = new StringWriter();
214+
215+
var context = new TestLoggerContext(
216+
new GitHubWorkflow(TextWriter.Null, summaryWriter),
217+
new TestLoggerOptions { SummaryIncludeNotFoundTests = false }
218+
);
219+
220+
// Act
221+
context.SimulateTestRun();
222+
223+
// Assert
224+
var output = summaryWriter.ToString().Trim();
225+
output.Should().BeNullOrEmpty();
226+
227+
testOutput.WriteLine(output);
228+
}
187229
}

GitHubActionsTestLogger/TestLoggerContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args)
133133
TestResults = testResults
134134
};
135135

136+
if (
137+
!Options.SummaryIncludeNotFoundTests
138+
&& testRunStatistics.OverallOutcome == TestOutcome.NotFound
139+
)
140+
return;
141+
136142
github.CreateSummary(template.Render());
137143
}
138144
}

GitHubActionsTestLogger/TestLoggerOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public partial class TestLoggerOptions
1212
public bool SummaryIncludePassedTests { get; init; }
1313

1414
public bool SummaryIncludeSkippedTests { get; init; }
15+
16+
public bool SummaryIncludeNotFoundTests { get; init; } = true;
1517
}
1618

1719
public partial class TestLoggerOptions
@@ -33,5 +35,8 @@ public static TestLoggerOptions Resolve(IReadOnlyDictionary<string, string?> par
3335
SummaryIncludeSkippedTests =
3436
parameters.GetValueOrDefault("summary.includeSkippedTests")?.Pipe(bool.Parse)
3537
?? Default.SummaryIncludeSkippedTests,
38+
SummaryIncludeNotFoundTests =
39+
parameters.GetValueOrDefault("summary.includeNotFoundTests")?.Pipe(bool.Parse)
40+
?? Default.SummaryIncludeSkippedTests
3641
};
3742
}

GitHubActionsTestLogger/TestRunStatistics.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public TestOutcome OverallOutcome
2424
if (SkippedTestCount > 0)
2525
return TestOutcome.Skipped;
2626

27+
if (TotalTestCount == 0)
28+
return TestOutcome.NotFound;
29+
2730
return TestOutcome.None;
2831
}
2932
}

GitHubActionsTestLogger/TestSummaryTemplate.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
{
2424
TestOutcome.Passed => "🟢",
2525
TestOutcome.Failed => "🔴",
26+
TestOutcome.NotFound => "⚪️",
2627
_ => "🟡"
2728
};
2829
}

Readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,16 @@ If you want to link skipped tests to their corresponding source definitions, mak
194194
**Default**: `false`.
195195

196196
> **Warning**:
197-
> If your test suite is really large, enabling this option may cause the summary to exceed the [maximum allowed size](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#step-isolation-and-limits).
197+
> If your test suite is really large, enabling this option may cause the summary to exceed the [maximum allowed size](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#step-isolation-and-limits).
198+
>
199+
200+
#### Include not found tests in summary
201+
202+
Use the `summary.includeNotFoundTests` option to specify whether test assemblies that did not yield any runnable tests should be included in the summary.
203+
204+
Using [test filters](https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests) might result in some test assemblies
205+
not yielding **any** tests. This might be done on purpose in which case reporting these may not be helpful.
206+
207+
The default behavior is to include test assemblies without any tests in the report.
208+
209+
**Default**: `true`.

0 commit comments

Comments
 (0)