Skip to content

Commit 5a1a7ff

Browse files
authored
Drop support for traits within annotation title/message format (#55)
1 parent 6263b36 commit 5a1a7ff

File tree

9 files changed

+8
-121
lines changed

9 files changed

+8
-121
lines changed

GitHubActionsTestLogger.Tests/Mtp/TestNodeBuilder.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using GitHubActionsTestLogger.Tests.Utils.Extensions;
43
using Microsoft.Testing.Platform.Extensions.Messages;
54

@@ -14,7 +13,6 @@ internal class TestNodeBuilder
1413
private string _methodName = "FakeTestMethod";
1514
private string? _sourceFilePath;
1615
private int? _sourceLineNumber;
17-
private readonly Dictionary<string, string> _traits = new(StringComparer.Ordinal);
1816
private TestOutcome _testOutcome;
1917
private string? _errorMessage;
2018
private string? _errorStackTrace;
@@ -61,12 +59,6 @@ public TestNodeBuilder SetSourceLineNumber(int sourceLineNumber)
6159
return this;
6260
}
6361

64-
public TestNodeBuilder SetTrait(string name, string value)
65-
{
66-
_traits[name] = value;
67-
return this;
68-
}
69-
7062
public TestNodeBuilder SetOutcome(TestOutcome testOutcome)
7163
{
7264
_testOutcome = testOutcome;
@@ -133,10 +125,6 @@ public TestNode Build()
133125
);
134126
}
135127

136-
// Traits
137-
foreach (var trait in _traits)
138-
properties.Add(new TestMetadataProperty(trait.Key, trait.Value));
139-
140128
return new TestNode
141129
{
142130
Uid = Guid.NewGuid().ToString(),

GitHubActionsTestLogger.Tests/MtpAnnotationSpecs.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -202,47 +202,6 @@ public async Task I_can_use_the_logger_to_produce_annotations_that_include_the_t
202202
testOutput.WriteLine(output);
203203
}
204204

205-
[Fact]
206-
public async Task I_can_use_the_logger_to_produce_annotations_that_include_test_traits()
207-
{
208-
// Arrange
209-
using var testResultsDir = TempDir.Create();
210-
await using var commandWriter = new StringWriter();
211-
212-
var builder = await TestApplication.CreateBuilderAsync([
213-
"--results-directory",
214-
testResultsDir.Path,
215-
"--report-github",
216-
"--report-github-annotations-title",
217-
"<@traits.Category -> @test>",
218-
"--report-github-annotations-message",
219-
"[@traits.Category -> @test]",
220-
]);
221-
222-
builder.RegisterFakeTests(
223-
new TestNodeBuilder()
224-
.SetDisplayName("Test1")
225-
.SetTrait("Category", "UI Test")
226-
.SetTrait("Document", "SS01")
227-
.SetOutcome(TestOutcome.Failed)
228-
.Build()
229-
);
230-
231-
builder.AddGitHubActionsReporting(commandWriter, TextWriter.Null);
232-
233-
// Act
234-
var app = await builder.BuildAsync();
235-
await app.RunAsync();
236-
237-
// Assert
238-
var output = commandWriter.ToString().Trim();
239-
240-
output.Should().Contain("<UI Test -> Test1>");
241-
output.Should().Contain("[UI Test -> Test1]");
242-
243-
testOutput.WriteLine(output);
244-
}
245-
246205
[Fact]
247206
public async Task I_can_use_the_logger_to_produce_annotations_that_include_the_error_message()
248207
{

GitHubActionsTestLogger.Tests/VsTest/TestResultBuilder.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public TestResultBuilder SetFullyQualifiedName(string fullyQualifiedName)
2727
return this;
2828
}
2929

30-
public TestResultBuilder SetTrait(string name, string value)
31-
{
32-
_testResult.TestCase.Traits.Add(name, value);
33-
return this;
34-
}
35-
3630
public TestResultBuilder SetOutcome(TestOutcome outcome)
3731
{
3832
_testResult.Outcome = outcome;

GitHubActionsTestLogger.Tests/VsTestAnnotationSpecs.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -177,45 +177,6 @@ public void I_can_use_the_logger_to_produce_annotations_that_include_the_test_na
177177
testOutput.WriteLine(output);
178178
}
179179

180-
[Fact]
181-
public void I_can_use_the_logger_to_produce_annotations_that_include_test_traits()
182-
{
183-
// Arrange
184-
using var commandWriter = new StringWriter();
185-
186-
var events = new FakeTestLoggerEvents();
187-
var logger = new VsTestLogger();
188-
189-
logger.Initialize(
190-
events,
191-
new Dictionary<string, string?>
192-
{
193-
["annotations-title"] = "<@traits.Category -> @test>",
194-
["annotations-message"] = "[@traits.Category -> @test]",
195-
},
196-
commandWriter,
197-
TextWriter.Null
198-
);
199-
200-
// Act
201-
events.SimulateTestRun(
202-
new TestResultBuilder()
203-
.SetDisplayName("Test1")
204-
.SetTrait("Category", "UI Test")
205-
.SetTrait("Document", "SS01")
206-
.SetOutcome(TestOutcome.Failed)
207-
.Build()
208-
);
209-
210-
// Assert
211-
var output = commandWriter.ToString().Trim();
212-
213-
output.Should().Contain("<UI Test -> Test1>");
214-
output.Should().Contain("[UI Test -> Test1]");
215-
216-
testOutput.WriteLine(output);
217-
}
218-
219180
[Fact]
220181
public void I_can_use_the_logger_to_produce_annotations_that_include_the_error_message()
221182
{

GitHubActionsTestLogger/MtpLogger.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.Linq;
54
using System.Reflection;
65
using System.Runtime.InteropServices;
76
using System.Threading;
@@ -94,10 +93,7 @@ CancellationToken cancellationToken
9493
message.TestNode.TryGetTypeFullyQualifiedName() ?? "<>"
9594
),
9695
message.TestNode.TryGetSourceFilePath(),
97-
message.TestNode.TryGetSourceLine(),
98-
message
99-
.TestNode.Properties.OfType<TestMetadataProperty>()
100-
.ToDictionary(p => p.Key, p => p.Value)
96+
message.TestNode.TryGetSourceLine()
10197
);
10298

10399
var testResult = new TestResult(
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System.Collections.Generic;
2-
3-
namespace GitHubActionsTestLogger.Reporting;
1+
namespace GitHubActionsTestLogger.Reporting;
42

53
internal record TestDefinition(
64
string Id,
75
string DisplayName,
86
SymbolReference Symbol,
97
SymbolReference TypeSymbol,
108
string? SourceFilePath,
11-
int? SourceFileLineNumber,
12-
IReadOnlyDictionary<string, string> Properties
9+
int? SourceFileLineNumber
1310
);

GitHubActionsTestLogger/Reporting/TestReportingContext.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ private string FormatAnnotation(string format, TestResult testResult)
2727
// Name
2828
buffer.Replace("@test", testResult.Definition.DisplayName);
2929

30-
// Properties
31-
foreach (var property in testResult.Definition.Properties)
32-
buffer.Replace($"@traits.{property.Key}", property.Value);
33-
3430
// Error message
3531
buffer.Replace("@error", testResult.ErrorMessage ?? "");
3632

GitHubActionsTestLogger/VsTestLogger.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ private void OnTestResult(TestResultEventArgs args)
109109
args.Result.TestCase.GetTypeFullyQualifiedName()
110110
),
111111
args.Result.TryGetSourceFilePath(),
112-
args.Result.TryGetSourceLine(),
113-
args.Result.Traits.Union(args.Result.TestCase.Traits)
114-
.ToDictionary(t => t.Name, t => t.Value)
112+
args.Result.TryGetSourceLine()
115113
);
116114

117115
var testResult = new TestResult(

Readme.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,16 @@ Use the `[--report-github-]annotations-title` option to specify the annotation t
186186

187187
The following replacement tokens are available:
188188

189-
- `@test` — replaced with the display name of the test
190-
- `@traits.TRAIT_NAME` — replaced with the value of the trait named `TRAIT_NAME`
191-
- `@error` — replaced with the error message
192-
- `@trace` — replaced with the stack trace
193-
- `@framework` — replaced with the target framework
189+
- `@test` — replaced with the display name of the test.
190+
- `@error` — replaced with the error message.
191+
- `@trace` — replaced with the stack trace.
192+
- `@framework` — replaced with the target framework.
194193

195194
**Default**: `@test`.
196195

197196
**Examples**:
198197

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

203201
#### Custom annotation message

0 commit comments

Comments
 (0)