Skip to content

Commit 2bcbdbd

Browse files
committed
Refactor
1 parent f3ad827 commit 2bcbdbd

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

Diff for: GitHubActionsTestLogger.Tests/SummarySpecs.cs

+30-30
Original file line numberDiff line numberDiff line change
@@ -80,113 +80,113 @@ public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_
8080
}
8181

8282
[Fact]
83-
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_skipped_tests()
83+
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_failed_tests()
8484
{
8585
// Arrange
8686
using var summaryWriter = new StringWriter();
8787

8888
var context = new TestLoggerContext(
8989
new GitHubWorkflow(TextWriter.Null, summaryWriter),
90-
new TestLoggerOptions { SummaryIncludeSkippedTests = true }
90+
TestLoggerOptions.Default
9191
);
9292

9393
// Act
9494
context.SimulateTestRun(
9595
new TestResultBuilder()
9696
.SetDisplayName("Test1")
9797
.SetFullyQualifiedName("TestProject.SomeTests.Test1")
98-
.SetOutcome(TestOutcome.Skipped)
98+
.SetOutcome(TestOutcome.Failed)
99+
.SetErrorMessage("ErrorMessage1")
99100
.Build(),
100101
new TestResultBuilder()
101102
.SetDisplayName("Test2")
102103
.SetFullyQualifiedName("TestProject.SomeTests.Test2")
103-
.SetOutcome(TestOutcome.Skipped)
104+
.SetOutcome(TestOutcome.Failed)
105+
.SetErrorMessage("ErrorMessage2")
104106
.Build(),
105107
new TestResultBuilder()
106108
.SetDisplayName("Test3")
107109
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
108-
.SetOutcome(TestOutcome.Skipped)
110+
.SetOutcome(TestOutcome.Failed)
111+
.SetErrorMessage("ErrorMessage3")
109112
.Build(),
110113
new TestResultBuilder()
111114
.SetDisplayName("Test4")
112115
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
113-
.SetOutcome(TestOutcome.Failed)
114-
.SetErrorMessage("ErrorMessage4")
116+
.SetOutcome(TestOutcome.Passed)
117+
.Build(),
118+
new TestResultBuilder()
119+
.SetDisplayName("Test5")
120+
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
121+
.SetOutcome(TestOutcome.Skipped)
115122
.Build()
116123
);
117124

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

121128
output.Should().Contain("Test1");
129+
output.Should().Contain("ErrorMessage1");
122130
output.Should().Contain("Test2");
131+
output.Should().Contain("ErrorMessage2");
123132
output.Should().Contain("Test3");
124-
output.Should().Contain("Test4");
133+
output.Should().Contain("ErrorMessage3");
134+
135+
output.Should().NotContain("Test4");
136+
output.Should().NotContain("Test5");
125137

126138
testOutput.WriteLine(output);
127139
}
128140

129141
[Fact]
130-
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_failed_tests()
142+
public void I_can_use_the_logger_to_produce_a_summary_that_includes_the_list_of_skipped_tests()
131143
{
132144
// Arrange
133145
using var summaryWriter = new StringWriter();
134146

135147
var context = new TestLoggerContext(
136148
new GitHubWorkflow(TextWriter.Null, summaryWriter),
137-
TestLoggerOptions.Default
149+
new TestLoggerOptions { SummaryIncludeSkippedTests = true }
138150
);
139151

140152
// Act
141153
context.SimulateTestRun(
142154
new TestResultBuilder()
143155
.SetDisplayName("Test1")
144156
.SetFullyQualifiedName("TestProject.SomeTests.Test1")
145-
.SetOutcome(TestOutcome.Failed)
146-
.SetErrorMessage("ErrorMessage1")
157+
.SetOutcome(TestOutcome.Skipped)
147158
.Build(),
148159
new TestResultBuilder()
149160
.SetDisplayName("Test2")
150161
.SetFullyQualifiedName("TestProject.SomeTests.Test2")
151-
.SetOutcome(TestOutcome.Failed)
152-
.SetErrorMessage("ErrorMessage2")
162+
.SetOutcome(TestOutcome.Skipped)
153163
.Build(),
154164
new TestResultBuilder()
155165
.SetDisplayName("Test3")
156166
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
157-
.SetOutcome(TestOutcome.Failed)
158-
.SetErrorMessage("ErrorMessage3")
167+
.SetOutcome(TestOutcome.Skipped)
159168
.Build(),
160169
new TestResultBuilder()
161170
.SetDisplayName("Test4")
162171
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
163-
.SetOutcome(TestOutcome.Passed)
164-
.Build(),
165-
new TestResultBuilder()
166-
.SetDisplayName("Test5")
167-
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
168-
.SetOutcome(TestOutcome.Skipped)
172+
.SetOutcome(TestOutcome.Failed)
173+
.SetErrorMessage("ErrorMessage4")
169174
.Build()
170175
);
171176

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

175180
output.Should().Contain("Test1");
176-
output.Should().Contain("ErrorMessage1");
177181
output.Should().Contain("Test2");
178-
output.Should().Contain("ErrorMessage2");
179182
output.Should().Contain("Test3");
180-
output.Should().Contain("ErrorMessage3");
181-
182-
output.Should().NotContain("Test4");
183-
output.Should().NotContain("Test5");
183+
output.Should().Contain("Test4");
184184

185185
testOutput.WriteLine(output);
186186
}
187187

188188
[Fact]
189-
public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_assemblies()
189+
public void I_can_use_the_logger_to_produce_a_summary_that_includes_empty_test_suites()
190190
{
191191
// Arrange
192192
using var summaryWriter = new StringWriter();
@@ -207,7 +207,7 @@ public void I_can_use_the_logger_to_produce_a_summary_that_reports_empty_test_as
207207
}
208208

209209
[Fact]
210-
public void I_can_use_the_logger_to_produce_no_summary_for_empty_test_assemblies_using_options()
210+
public void I_can_use_the_logger_to_produce_a_summary_that_does_not_include_empty_test_suites()
211211
{
212212
// Arrange
213213
using var summaryWriter = new StringWriter();

Diff for: GitHubActionsTestLogger/TestLoggerContext.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class TestLoggerContext(GitHubWorkflow github, TestLoggerOptions options)
1313
{
1414
private readonly object _lock = new();
1515
private TestRunCriteria? _testRunCriteria;
16-
private readonly List<TestResult> _testResults = new();
16+
private readonly List<TestResult> _testResults = [];
1717

1818
public TestLoggerOptions Options { get; } = options;
1919

@@ -137,7 +137,9 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs args)
137137
!Options.SummaryIncludeNotFoundTests
138138
&& testRunStatistics.OverallOutcome == TestOutcome.NotFound
139139
)
140+
{
140141
return;
142+
}
141143

142144
github.CreateSummary(template.Render());
143145
}

Diff for: GitHubActionsTestLogger/TestSummaryTemplate.cshtml

+8-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
{
2424
TestOutcome.Passed => "🟢",
2525
TestOutcome.Failed => "🔴",
26+
TestOutcome.Skipped => "🟡",
2627
TestOutcome.NotFound => "⚪️",
27-
_ => "🟡"
28+
_ => "\u2753"
2829
};
2930
}
3031

@@ -107,10 +108,12 @@
107108
{
108109
TestOutcome.Passed => "🟩",
109110
TestOutcome.Failed => "🟥",
110-
_ => "🟨"
111+
TestOutcome.Skipped => "🟨",
112+
TestOutcome.NotFound => "",
113+
_ => "\u2753"
111114
};
112115

113-
// Use display name if it's different from the fully qualified name,
116+
// Use the display name if it's different from the fully qualified name,
114117
// otherwise use the minimally qualified name.
115118
var testName = !string.Equals(
116119
testResult.TestCase.DisplayName,
@@ -179,8 +182,8 @@
179182
}
180183
}
181184

182-
// Using params here to write multiple lines as a workaround
183-
// for the fact that Razor does not support raw string literals.
185+
// Using params here to write multiple lines as a workaround for the
186+
// fact that Razor does not support multiline raw string literals.
184187
private void WriteMarkdown(params string?[] lines)
185188
{
186189
// Two line breaks are required to separate markdown from HTML

0 commit comments

Comments
 (0)