Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 29, 2024
1 parent f3ad827 commit 2bcbdbd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
60 changes: 30 additions & 30 deletions GitHubActionsTestLogger.Tests/SummarySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,113 +80,113 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
}

[Fact]
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_skipped_tests()
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_failed_tests()
{
// Arrange
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(TextWriter.Null, summaryWriter),
new TestLoggerOptions { SummaryIncludeSkippedTests = true }
TestLoggerOptions.Default
);

// Act
context.SimulateTestRun(
new TestResultBuilder()
.SetDisplayName("Test1")
.SetFullyQualifiedName("TestProject.SomeTests.Test1")
.SetOutcome(TestOutcome.Skipped)
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage1")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test2")
.SetFullyQualifiedName("TestProject.SomeTests.Test2")
.SetOutcome(TestOutcome.Skipped)
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage2")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test3")
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
.SetOutcome(TestOutcome.Skipped)
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage3")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test4")
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage4")
.SetOutcome(TestOutcome.Passed)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test5")
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
.SetOutcome(TestOutcome.Skipped)
.Build()
);

// Assert
var output = summaryWriter.ToString().Trim();

output.Should().Contain("Test1");
output.Should().Contain("ErrorMessage1");
output.Should().Contain("Test2");
output.Should().Contain("ErrorMessage2");
output.Should().Contain("Test3");
output.Should().Contain("Test4");
output.Should().Contain("ErrorMessage3");

output.Should().NotContain("Test4");
output.Should().NotContain("Test5");

testOutput.WriteLine(output);
}

[Fact]
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_failed_tests()
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_skipped_tests()
{
// Arrange
using var summaryWriter = new StringWriter();

var context = new TestLoggerContext(
new GitHubWorkflow(TextWriter.Null, summaryWriter),
TestLoggerOptions.Default
new TestLoggerOptions { SummaryIncludeSkippedTests = true }
);

// Act
context.SimulateTestRun(
new TestResultBuilder()
.SetDisplayName("Test1")
.SetFullyQualifiedName("TestProject.SomeTests.Test1")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage1")
.SetOutcome(TestOutcome.Skipped)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test2")
.SetFullyQualifiedName("TestProject.SomeTests.Test2")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage2")
.SetOutcome(TestOutcome.Skipped)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test3")
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage3")
.SetOutcome(TestOutcome.Skipped)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test4")
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
.SetOutcome(TestOutcome.Passed)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test5")
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
.SetOutcome(TestOutcome.Skipped)
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage4")
.Build()
);

// Assert
var output = summaryWriter.ToString().Trim();

output.Should().Contain("Test1");
output.Should().Contain("ErrorMessage1");
output.Should().Contain("Test2");
output.Should().Contain("ErrorMessage2");
output.Should().Contain("Test3");
output.Should().Contain("ErrorMessage3");

output.Should().NotContain("Test4");
output.Should().NotContain("Test5");
output.Should().Contain("Test4");

testOutput.WriteLine(output);
}

[Fact]
public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_assemblies()
public void I_can_use_the_logger_to_produce_a_summary_that_includes_empty_test_suites()
{
// Arrange
using var summaryWriter = new StringWriter();
Expand All @@ -207,7 +207,7 @@ public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_as
}

[Fact]
public void I_can_use_the_logger_to_produce_no_summary_for_empty_test_assemblies_using_options()
public void I_can_use_the_logger_to_produce_a_summary_that_does_not_include_empty_test_suites()
{
// Arrange
using var summaryWriter = new StringWriter();
Expand Down
4 changes: 3 additions & 1 deletion GitHubActionsTestLogger/TestLoggerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TestLoggerContext(GitHubWorkflow github, TestLoggerOptions options)
{
private readonly object _lock = new();
private TestRunCriteria? _testRunCriteria;
private readonly List<TestResult> _testResults = new();
private readonly List<TestResult> _testResults = [];

public TestLoggerOptions Options { get; } = options;

Expand Down Expand Up @@ -137,7 +137,9 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args)
!Options.SummaryIncludeNotFoundTests
&& testRunStatistics.OverallOutcome == TestOutcome.NotFound
)
{
return;
}

github.CreateSummary(template.Render());
}
Expand Down
13 changes: 8 additions & 5 deletions GitHubActionsTestLogger/TestSummaryTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
{
TestOutcome.Passed => "🟢",
TestOutcome.Failed => "🔴",
TestOutcome.Skipped => "🟡",
TestOutcome.NotFound => "⚪️",
_ => "🟡"
_ => "\u2753"
};
}

Expand Down Expand Up @@ -107,10 +108,12 @@
{
TestOutcome.Passed => "🟩",
TestOutcome.Failed => "🟥",
_ => "🟨"
TestOutcome.Skipped => "🟨",
TestOutcome.NotFound => "",
_ => "\u2753"
};

// Use display name if it's different from the fully qualified name,
// Use the display name if it's different from the fully qualified name,
// otherwise use the minimally qualified name.
var testName = !string.Equals(
testResult.TestCase.DisplayName,
Expand Down Expand Up @@ -179,8 +182,8 @@
}
}

// Using params here to write multiple lines as a workaround
// for the fact that Razor does not support raw string literals.
// Using params here to write multiple lines as a workaround for the
// fact that Razor does not support multiline raw string literals.
private void WriteMarkdown(params string?[] lines)
{
// Two line breaks are required to separate markdown from HTML
Expand Down

0 comments on commit 2bcbdbd

Please sign in to comment.