Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing skip reason (#3754) #3755

Merged
merged 1 commit into from
Sep 3, 2024
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
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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoRossignoli readonly property.


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