diff --git a/GitHubActionsTestLogger.Tests/SummarySpecs.cs b/GitHubActionsTestLogger.Tests/SummarySpecs.cs index 1a11ddf..25edc20 100644 --- a/GitHubActionsTestLogger.Tests/SummarySpecs.cs +++ b/GitHubActionsTestLogger.Tests/SummarySpecs.cs @@ -184,4 +184,46 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_ testOutput.WriteLine(output); } + + [Fact] + public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_assemblies() + { + // Arrange + using var summaryWriter = new StringWriter(); + + var context = new TestLoggerContext( + new GitHubWorkflow(TextWriter.Null, summaryWriter), + TestLoggerOptions.Default + ); + + // Act + context.SimulateTestRun(); + + // Assert + var output = summaryWriter.ToString().Trim(); + output.Should().Contain("⚪️ FakeTests"); + + testOutput.WriteLine(output); + } + + [Fact] + public void I_can_use_the_logger_to_produce_no_summary_for_empty_test_assemblies_using_options() + { + // Arrange + using var summaryWriter = new StringWriter(); + + var context = new TestLoggerContext( + new GitHubWorkflow(TextWriter.Null, summaryWriter), + new TestLoggerOptions { SummaryIncludeNotFoundTests = false } + ); + + // Act + context.SimulateTestRun(); + + // Assert + var output = summaryWriter.ToString().Trim(); + output.Should().BeNullOrEmpty(); + + testOutput.WriteLine(output); + } } diff --git a/GitHubActionsTestLogger/TestLoggerContext.cs b/GitHubActionsTestLogger/TestLoggerContext.cs index 4dc1d3e..0864f92 100644 --- a/GitHubActionsTestLogger/TestLoggerContext.cs +++ b/GitHubActionsTestLogger/TestLoggerContext.cs @@ -133,6 +133,12 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args) TestResults = testResults }; + if ( + !Options.SummaryIncludeNotFoundTests + && testRunStatistics.OverallOutcome == TestOutcome.NotFound + ) + return; + github.CreateSummary(template.Render()); } } diff --git a/GitHubActionsTestLogger/TestLoggerOptions.cs b/GitHubActionsTestLogger/TestLoggerOptions.cs index c1cb186..2758afd 100644 --- a/GitHubActionsTestLogger/TestLoggerOptions.cs +++ b/GitHubActionsTestLogger/TestLoggerOptions.cs @@ -12,6 +12,8 @@ public partial class TestLoggerOptions public bool SummaryIncludePassedTests { get; init; } public bool SummaryIncludeSkippedTests { get; init; } + + public bool SummaryIncludeNotFoundTests { get; init; } = true; } public partial class TestLoggerOptions @@ -33,5 +35,8 @@ public static TestLoggerOptions Resolve(IReadOnlyDictionary par SummaryIncludeSkippedTests = parameters.GetValueOrDefault("summary.includeSkippedTests")?.Pipe(bool.Parse) ?? Default.SummaryIncludeSkippedTests, + SummaryIncludeNotFoundTests = + parameters.GetValueOrDefault("summary.includeNotFoundTests")?.Pipe(bool.Parse) + ?? Default.SummaryIncludeSkippedTests }; } diff --git a/GitHubActionsTestLogger/TestRunStatistics.cs b/GitHubActionsTestLogger/TestRunStatistics.cs index 787b887..8c9fcd2 100644 --- a/GitHubActionsTestLogger/TestRunStatistics.cs +++ b/GitHubActionsTestLogger/TestRunStatistics.cs @@ -24,6 +24,9 @@ public TestOutcome OverallOutcome if (SkippedTestCount > 0) return TestOutcome.Skipped; + if (TotalTestCount == 0) + return TestOutcome.NotFound; + return TestOutcome.None; } } diff --git a/GitHubActionsTestLogger/TestSummaryTemplate.cshtml b/GitHubActionsTestLogger/TestSummaryTemplate.cshtml index 8238179..c34cb74 100644 --- a/GitHubActionsTestLogger/TestSummaryTemplate.cshtml +++ b/GitHubActionsTestLogger/TestSummaryTemplate.cshtml @@ -23,6 +23,7 @@ { TestOutcome.Passed => "🟢", TestOutcome.Failed => "🔴", + TestOutcome.NotFound => "⚪️", _ => "🟡" }; } diff --git a/Readme.md b/Readme.md index 3e7ff1e..bc62745 100644 --- a/Readme.md +++ b/Readme.md @@ -194,4 +194,16 @@ If you want to link skipped tests to their corresponding source definitions, mak **Default**: `false`. > **Warning**: -> 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). \ No newline at end of file +> 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). +> + +#### Include not found tests in summary + +Use the `summary.includeNotFoundTests` option to specify whether test assemblies that did not yield any runnable tests should be included in the summary. + +Using [test filters](https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests) might result in some test assemblies +not yielding **any** tests. This might be done on purpose in which case reporting these may not be helpful. + +The default behavior is to include test assemblies without any tests in the report. + +**Default**: `true`.