Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for not reporting empty test assemblies #26

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 12 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ 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 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`.
Tyrrrz marked this conversation as resolved.
Show resolved Hide resolved