Skip to content

Commit

Permalink
Fix missing skip reason (#3754) (#3755)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoRossignoli committed Sep 3, 2024
1 parent ccf7de7 commit f701df6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace TestingPlatformExplorer.TestingFramework;
[AttributeUsage(AttributeTargets.Method)]
public class SkipAttribute : Attribute
{
public string Reason { get; private set; }

public SkipAttribute(string reason)
{
Reason = reason;
}
}

[AttributeUsage(AttributeTargets.Method)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
}
}

if (test.GetCustomAttribute<SkipAttribute>() != null)
SkipAttribute? skipAttribute = test.GetCustomAttribute<SkipAttribute>();
if (skipAttribute != null)
{
var skippedTestNode = new TestNode()
{
Uid = $"{test.DeclaringType!.FullName}.{test.Name}",
DisplayName = test.Name,
Properties = new PropertyBag(SkippedTestNodeStateProperty.CachedInstance),
Properties = new PropertyBag(new SkippedTestNodeStateProperty(skipAttribute.Reason)),
};

if (_capabilities.TrxCapability.IsTrxEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void TestMethod3(ITestOutputHelper testOutputHelper)
}
}

[Skip]
[Skip("Temporary disabled")]
[TestMethod]
public static void TestMethod4() => Assert.AreEqual(1, 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ public Json(Dictionary<Type, JsonSerializer>? serializers = null, Dictionary<Typ
break;
}
case SkippedTestNodeStateProperty:
case SkippedTestNodeStateProperty skippedTestNodeStateProperty:
{
properties.Add(("execution-state", "skipped"));
if (!RoslynString.IsNullOrEmpty(skippedTestNodeStateProperty.Explanation))
{
properties.Add(("error.message", skippedTestNodeStateProperty.Explanation));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,15 @@ static SerializerUtilities()
break;
}
case SkippedTestNodeStateProperty:
case SkippedTestNodeStateProperty skippedTestNodeStateProperty:
{
properties["execution-state"] = "skipped";
if (!RoslynString.IsNullOrEmpty(skippedTestNodeStateProperty.Explanation))
{
properties["error.message"] = skippedTestNodeStateProperty.Explanation;
}
break;
}
Expand Down

0 comments on commit f701df6

Please sign in to comment.