Skip to content

Commit

Permalink
Add support for not reporting empty test assemblies (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored May 29, 2024
1 parent bf14ebd commit f3ad827
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
42 changes: 42 additions & 0 deletions GitHubActionsTestLogger.Tests/SummarySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions GitHubActionsTestLogger/TestLoggerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args)
TestResults = testResults
};

if (
!Options.SummaryIncludeNotFoundTests
&& testRunStatistics.OverallOutcome == TestOutcome.NotFound
)
return;

github.CreateSummary(template.Render());
}
}
Expand Down
5 changes: 5 additions & 0 deletions GitHubActionsTestLogger/TestLoggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +35,8 @@ public static TestLoggerOptions Resolve(IReadOnlyDictionary<string, string?> par
SummaryIncludeSkippedTests =
parameters.GetValueOrDefault("summary.includeSkippedTests")?.Pipe(bool.Parse)
?? Default.SummaryIncludeSkippedTests,
SummaryIncludeNotFoundTests =
parameters.GetValueOrDefault("summary.includeNotFoundTests")?.Pipe(bool.Parse)
?? Default.SummaryIncludeSkippedTests
};
}
3 changes: 3 additions & 0 deletions GitHubActionsTestLogger/TestRunStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public TestOutcome OverallOutcome
if (SkippedTestCount > 0)
return TestOutcome.Skipped;

if (TotalTestCount == 0)
return TestOutcome.NotFound;

return TestOutcome.None;
}
}
Expand Down
1 change: 1 addition & 0 deletions GitHubActionsTestLogger/TestSummaryTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{
TestOutcome.Passed => "🟢",
TestOutcome.Failed => "🔴",
TestOutcome.NotFound => "⚪️",
_ => "🟡"
};
}
Expand Down
14 changes: 13 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
> 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`.

0 comments on commit f3ad827

Please sign in to comment.