Skip to content

Commit

Permalink
Add options to include passed and skipped tests in the summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 9, 2023
1 parent 3df3dd9 commit f03b68a
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 38 deletions.
20 changes: 20 additions & 0 deletions GitHubActionsTestLogger.Tests/AnnotationFormatSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
using GitHubActionsTestLogger.Tests.Utils.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Xunit;
using Xunit.Abstractions;

namespace GitHubActionsTestLogger.Tests;

public class AnnotationFormatSpecs
{
private readonly ITestOutputHelper _testOutput;

public AnnotationFormatSpecs(ITestOutputHelper testOutput) =>
_testOutput = testOutput;

[Fact]
public void Custom_format_can_reference_test_name()
{
Expand Down Expand Up @@ -40,6 +46,8 @@ public void Custom_format_can_reference_test_name()

output.Should().Contain("<Test1>");
output.Should().Contain("[Test1]");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -75,6 +83,8 @@ public void Custom_format_can_reference_test_traits()

output.Should().Contain("<UI Test -> Test1>");
output.Should().Contain("[UI Test -> Test1]");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -109,6 +119,8 @@ public void Custom_format_can_reference_test_error_message()

output.Should().Contain("<Test1: ErrorMessage>");
output.Should().Contain("[Test1: ErrorMessage]");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -143,6 +155,8 @@ public void Custom_format_can_reference_test_error_stacktrace()

output.Should().Contain("<Test1: ErrorStackTrace>");
output.Should().Contain("[Test1: ErrorStackTrace]");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -179,6 +193,8 @@ public void Custom_format_can_reference_test_target_framework_name()

output.Should().Contain("<Test1 (FakeTargetFramework)>");
output.Should().Contain("[Test1 (FakeTargetFramework)]");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -210,6 +226,8 @@ public void Custom_format_can_contain_newlines()
var output = commandWriter.ToString().Trim();

output.Should().Contain("foo%0Abar");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -240,5 +258,7 @@ public void Default_format_references_test_name_and_error_message()

output.Should().Contain("Test1");
output.Should().Contain("ErrorMessage");

_testOutput.WriteLine(output);
}
}
14 changes: 14 additions & 0 deletions GitHubActionsTestLogger.Tests/AnnotationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
using GitHubActionsTestLogger.Tests.Utils.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Xunit;
using Xunit.Abstractions;

namespace GitHubActionsTestLogger.Tests;

public class AnnotationSpecs
{
private readonly ITestOutputHelper _testOutput;

public AnnotationSpecs(ITestOutputHelper testOutput) =>
_testOutput = testOutput;

[Fact]
public void Passed_tests_do_not_get_reported()
{
Expand Down Expand Up @@ -95,6 +101,8 @@ public void Failed_tests_get_reported()
output.Should().StartWith("::error ");
output.Should().Contain("Test1");
output.Should().Contain("ErrorMessage");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -146,6 +154,8 @@ at CliWrap.Tests.CancellationSpecs.I_can_execute_a_command_with_buffering_and_ca
output.Should().Contain("line=75");
output.Should().Contain("I can execute a command with buffering and cancel it immediately");
output.Should().Contain("ErrorMessage");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -201,6 +211,8 @@ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotifi
output.Should().Contain("line=187");
output.Should().Contain("SendEnvelopeAsync_ItemRateLimit_DropsItem");
output.Should().Contain("ErrorMessage");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -234,5 +246,7 @@ public void Failed_tests_get_reported_with_approximate_source_information_if_exc
output.Should().MatchRegex(@"file=.*?\.csproj");
output.Should().Contain("Test1");
output.Should().Contain("ErrorMessage");

_testOutput.WriteLine(output);
}
}
6 changes: 5 additions & 1 deletion GitHubActionsTestLogger.Tests/InitializationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public void Logger_can_be_used_with_custom_configuration()
var parameters = new Dictionary<string, string?>
{
["annotations.titleFormat"] = "TitleFormat",
["annotations.messageFormat"] = "MessageFormat"
["annotations.messageFormat"] = "MessageFormat",
["summary.includePassedTests"] = "true",
["summary.includeSkippedTests"] = "true"
};

// Act
Expand All @@ -43,5 +45,7 @@ public void Logger_can_be_used_with_custom_configuration()
logger.Context.Should().NotBeNull();
logger.Context?.Options.AnnotationTitleFormat.Should().Be("TitleFormat");
logger.Context?.Options.AnnotationMessageFormat.Should().Be("MessageFormat");
logger.Context?.Options.SummaryIncludePassedTests.Should().BeTrue();
logger.Context?.Options.SummaryIncludeSkippedTests.Should().BeTrue();
}
}
140 changes: 140 additions & 0 deletions GitHubActionsTestLogger.Tests/SummarySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
using GitHubActionsTestLogger.Tests.Utils.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Xunit;
using Xunit.Abstractions;

namespace GitHubActionsTestLogger.Tests;

public class SummarySpecs
{
private readonly ITestOutputHelper _testOutput;

public SummarySpecs(ITestOutputHelper testOutput) =>
_testOutput = testOutput;

[Fact]
public void Test_summary_contains_test_suite_name()
{
Expand All @@ -30,6 +36,114 @@ public void Test_summary_contains_test_suite_name()
var output = summaryWriter.ToString().Trim();

output.Should().Contain("TestProject");

_testOutput.WriteLine(output);
}

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

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

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

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

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

_testOutput.WriteLine(output);
}

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

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

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

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

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

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -65,6 +179,16 @@ public void Test_summary_contains_names_of_failed_tests()
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage3")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test4")
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
.SetOutcome(TestOutcome.Passed)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test5")
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
.SetOutcome(TestOutcome.Skipped)
.Build()
);

Expand All @@ -74,6 +198,10 @@ public void Test_summary_contains_names_of_failed_tests()
output.Should().Contain("Test1");
output.Should().Contain("Test2");
output.Should().Contain("Test3");
output.Should().NotContain("Test4");
output.Should().NotContain("Test5");

_testOutput.WriteLine(output);
}

[Fact]
Expand Down Expand Up @@ -109,6 +237,16 @@ public void Test_summary_contains_error_messages_of_failed_tests()
.SetFullyQualifiedName("TestProject.SomeTests.Test3")
.SetOutcome(TestOutcome.Failed)
.SetErrorMessage("ErrorMessage3")
.Build(),
new TestResultBuilder()
.SetDisplayName("Test4")
.SetFullyQualifiedName("TestProject.SomeTests.Test4")
.SetOutcome(TestOutcome.Passed)
.Build(),
new TestResultBuilder()
.SetDisplayName("Test5")
.SetFullyQualifiedName("TestProject.SomeTests.Test5")
.SetOutcome(TestOutcome.Skipped)
.Build()
);

Expand All @@ -118,5 +256,7 @@ public void Test_summary_contains_error_messages_of_failed_tests()
output.Should().Contain("ErrorMessage1");
output.Should().Contain("ErrorMessage2");
output.Should().Contain("ErrorMessage3");

_testOutput.WriteLine(output);
}
}
Loading

0 comments on commit f03b68a

Please sign in to comment.