Skip to content

Commit f701df6

Browse files
Fix missing skip reason (#3754) (#3755)
1 parent ccf7de7 commit f701df6

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

docs/testingplatform/Source/TestingPlatformExplorer/TestingFramework/TestingFramework.Attributes.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ namespace TestingPlatformExplorer.TestingFramework;
66
[AttributeUsage(AttributeTargets.Method)]
77
public class SkipAttribute : Attribute
88
{
9+
public string Reason { get; private set; }
10+
11+
public SkipAttribute(string reason)
12+
{
13+
Reason = reason;
14+
}
915
}
1016

1117
[AttributeUsage(AttributeTargets.Method)]

docs/testingplatform/Source/TestingPlatformExplorer/TestingFramework/TestingFramework.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
152152
}
153153
}
154154

155-
if (test.GetCustomAttribute<SkipAttribute>() != null)
155+
SkipAttribute? skipAttribute = test.GetCustomAttribute<SkipAttribute>();
156+
if (skipAttribute != null)
156157
{
157158
var skippedTestNode = new TestNode()
158159
{
159160
Uid = $"{test.DeclaringType!.FullName}.{test.Name}",
160161
DisplayName = test.Name,
161-
Properties = new PropertyBag(SkippedTestNodeStateProperty.CachedInstance),
162+
Properties = new PropertyBag(new SkippedTestNodeStateProperty(skipAttribute.Reason)),
162163
};
163164

164165
if (_capabilities.TrxCapability.IsTrxEnabled)

docs/testingplatform/Source/TestingPlatformExplorer/UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void TestMethod3(ITestOutputHelper testOutputHelper)
3333
}
3434
}
3535

36-
[Skip]
36+
[Skip("Temporary disabled")]
3737
[TestMethod]
3838
public static void TestMethod4() => Assert.AreEqual(1, 1);
3939
}

src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Json.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,14 @@ public Json(Dictionary<Type, JsonSerializer>? serializers = null, Dictionary<Typ
210210
break;
211211
}
212212

213-
case SkippedTestNodeStateProperty:
213+
case SkippedTestNodeStateProperty skippedTestNodeStateProperty:
214214
{
215215
properties.Add(("execution-state", "skipped"));
216+
if (!RoslynString.IsNullOrEmpty(skippedTestNodeStateProperty.Explanation))
217+
{
218+
properties.Add(("error.message", skippedTestNodeStateProperty.Explanation));
219+
}
220+
216221
break;
217222
}
218223

src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,15 @@ static SerializerUtilities()
284284
break;
285285
}
286286

287-
case SkippedTestNodeStateProperty:
287+
case SkippedTestNodeStateProperty skippedTestNodeStateProperty:
288288
{
289289
properties["execution-state"] = "skipped";
290+
291+
if (!RoslynString.IsNullOrEmpty(skippedTestNodeStateProperty.Explanation))
292+
{
293+
properties["error.message"] = skippedTestNodeStateProperty.Explanation;
294+
}
295+
290296
break;
291297
}
292298

0 commit comments

Comments
 (0)