From abe4b3dfee5157cf1b9f4ed5ee8331c61e8c3c2c Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 29 May 2024 13:56:23 +0200 Subject: [PATCH 1/3] Add support for not reporting empty test assemblies --- GitHubActionsTestLogger.Tests/SummarySpecs.cs | 42 +++++++++++++++++++ GitHubActionsTestLogger/TestLoggerContext.cs | 6 +++ GitHubActionsTestLogger/TestLoggerOptions.cs | 5 +++ GitHubActionsTestLogger/TestRunStatistics.cs | 3 ++ .../TestSummaryTemplate.cshtml | 1 + Readme.md | 16 ++++++- 6 files changed, 72 insertions(+), 1 deletion(-) 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..5adbcb3 100644 --- a/Readme.md +++ b/Readme.md @@ -194,4 +194,18 @@ 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 tests to run should be included. + +Using [test filters](https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests?pivots=mstest) 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`. + +> **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). From 4d3d08ee76f10eff68a38af39f9591284d4b8b49 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 29 May 2024 14:03:10 +0200 Subject: [PATCH 2/3] remove warning from docs --- Readme.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/Readme.md b/Readme.md index 5adbcb3..3d4f538 100644 --- a/Readme.md +++ b/Readme.md @@ -206,6 +206,3 @@ not yielding **any** tests. This might be done on purpose in which case reportin The default behavior is to include test assemblies without any tests in the report. **Default**: `true`. - -> **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). From 946ae7d95766ecd60e3d8f7bebd888e64af7d56c Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 29 May 2024 22:32:37 +0300 Subject: [PATCH 3/3] Update Readme.md --- Readme.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 3d4f538..bc62745 100644 --- a/Readme.md +++ b/Readme.md @@ -196,11 +196,12 @@ If you want to link skipped tests to their corresponding source definitions, mak > **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). > + #### Include not found tests in summary -Use the `summary.includeNotFoundTests` option to specify whether test assemblies that did not yield any tests to run should be included. +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?pivots=mstest) might result in some test assemblies +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.