Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 0 additions & 12 deletions GitHubActionsTestLogger.Tests/Mtp/TestNodeBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using GitHubActionsTestLogger.Tests.Utils.Extensions;
using Microsoft.Testing.Platform.Extensions.Messages;

Expand All @@ -14,7 +13,6 @@ internal class TestNodeBuilder
private string _methodName = "FakeTestMethod";
private string? _sourceFilePath;
private int? _sourceLineNumber;
private readonly Dictionary<string, string> _traits = new(StringComparer.Ordinal);
private TestOutcome _testOutcome;
private string? _errorMessage;
private string? _errorStackTrace;
Expand Down Expand Up @@ -61,12 +59,6 @@ public TestNodeBuilder SetSourceLineNumber(int sourceLineNumber)
return this;
}

public TestNodeBuilder SetTrait(string name, string value)
{
_traits[name] = value;
return this;
}

public TestNodeBuilder SetOutcome(TestOutcome testOutcome)
{
_testOutcome = testOutcome;
Expand Down Expand Up @@ -133,10 +125,6 @@ public TestNode Build()
);
}

// Traits
foreach (var trait in _traits)
properties.Add(new TestMetadataProperty(trait.Key, trait.Value));

return new TestNode
{
Uid = Guid.NewGuid().ToString(),
Expand Down
41 changes: 0 additions & 41 deletions GitHubActionsTestLogger.Tests/MtpAnnotationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,47 +202,6 @@ public async Task I_can_use_the_logger_to_produce_annotations_that_include_the_t
testOutput.WriteLine(output);
}

[Fact]
public async Task I_can_use_the_logger_to_produce_annotations_that_include_test_traits()
{
// Arrange
using var testResultsDir = TempDir.Create();
await using var commandWriter = new StringWriter();

var builder = await TestApplication.CreateBuilderAsync([
"--results-directory",
testResultsDir.Path,
"--report-github",
"--report-github-annotations-title",
"<@traits.Category -> @test>",
"--report-github-annotations-message",
"[@traits.Category -> @test]",
]);

builder.RegisterFakeTests(
new TestNodeBuilder()
.SetDisplayName("Test1")
.SetTrait("Category", "UI Test")
.SetTrait("Document", "SS01")
.SetOutcome(TestOutcome.Failed)
.Build()
);

builder.AddGitHubActionsReporting(commandWriter, TextWriter.Null);

// Act
var app = await builder.BuildAsync();
await app.RunAsync();

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

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

testOutput.WriteLine(output);
}

[Fact]
public async Task I_can_use_the_logger_to_produce_annotations_that_include_the_error_message()
{
Expand Down
6 changes: 0 additions & 6 deletions GitHubActionsTestLogger.Tests/VsTest/TestResultBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ public TestResultBuilder SetFullyQualifiedName(string fullyQualifiedName)
return this;
}

public TestResultBuilder SetTrait(string name, string value)
{
_testResult.TestCase.Traits.Add(name, value);
return this;
}

public TestResultBuilder SetOutcome(TestOutcome outcome)
{
_testResult.Outcome = outcome;
Expand Down
39 changes: 0 additions & 39 deletions GitHubActionsTestLogger.Tests/VsTestAnnotationSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,45 +177,6 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_test_na
testOutput.WriteLine(output);
}

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

var events = new FakeTestLoggerEvents();
var logger = new VsTestLogger();

logger.Initialize(
events,
new Dictionary<string, string?>
{
["annotations-title"] = "<@traits.Category -> @test>",
["annotations-message"] = "[@traits.Category -> @test]",
},
commandWriter,
TextWriter.Null
);

// Act
events.SimulateTestRun(
new TestResultBuilder()
.SetDisplayName("Test1")
.SetTrait("Category", "UI Test")
.SetTrait("Document", "SS01")
.SetOutcome(TestOutcome.Failed)
.Build()
);

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

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

testOutput.WriteLine(output);
}

[Fact]
public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_message()
{
Expand Down
6 changes: 1 addition & 5 deletions GitHubActionsTestLogger/MtpLogger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -94,10 +93,7 @@ CancellationToken cancellationToken
message.TestNode.TryGetTypeFullyQualifiedName() ?? "<>"
),
message.TestNode.TryGetSourceFilePath(),
message.TestNode.TryGetSourceLine(),
message
.TestNode.Properties.OfType<TestMetadataProperty>()
.ToDictionary(p => p.Key, p => p.Value)
message.TestNode.TryGetSourceLine()
);

var testResult = new TestResult(
Expand Down
7 changes: 2 additions & 5 deletions GitHubActionsTestLogger/Reporting/TestDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Collections.Generic;

namespace GitHubActionsTestLogger.Reporting;
namespace GitHubActionsTestLogger.Reporting;

internal record TestDefinition(
string Id,
string DisplayName,
SymbolReference Symbol,
SymbolReference TypeSymbol,
string? SourceFilePath,
int? SourceFileLineNumber,
IReadOnlyDictionary<string, string> Properties
int? SourceFileLineNumber
);
4 changes: 0 additions & 4 deletions GitHubActionsTestLogger/Reporting/TestReportingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ private string FormatAnnotation(string format, TestResult testResult)
// Name
buffer.Replace("@test", testResult.Definition.DisplayName);

// Properties
foreach (var property in testResult.Definition.Properties)
buffer.Replace($"@traits.{property.Key}", property.Value);

// Error message
buffer.Replace("@error", testResult.ErrorMessage ?? "");

Expand Down
4 changes: 1 addition & 3 deletions GitHubActionsTestLogger/VsTestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ private void OnTestResult(TestResultEventArgs args)
args.Result.TestCase.GetTypeFullyQualifiedName()
),
args.Result.TryGetSourceFilePath(),
args.Result.TryGetSourceLine(),
args.Result.Traits.Union(args.Result.TestCase.Traits)
.ToDictionary(t => t.Name, t => t.Value)
args.Result.TryGetSourceLine()
);

var testResult = new TestResult(
Expand Down
10 changes: 4 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,16 @@ Use the `[--report-github-]annotations-title` option to specify the annotation t

The following replacement tokens are available:

- `@test` — replaced with the display name of the test
- `@traits.TRAIT_NAME` — replaced with the value of the trait named `TRAIT_NAME`
- `@error` — replaced with the error message
- `@trace` — replaced with the stack trace
- `@framework` — replaced with the target framework
- `@test` — replaced with the display name of the test.
- `@error` — replaced with the error message.
- `@trace` — replaced with the stack trace.
- `@framework` — replaced with the target framework.

**Default**: `@test`.

**Examples**:

- `@test` → `MyTests.Test1`
- `[@traits.Category] @test` → `[UI Tests] MyTests.Test1`
- `@test (@framework)` → `MyTests.Test1 (.NETCoreApp,Version=v6.0)`

#### Custom annotation message
Expand Down
Loading