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

Add traits to a TestNode properties #4007

Closed
thomhurst opened this issue Nov 5, 2024 · 7 comments · Fixed by #4041
Closed

Add traits to a TestNode properties #4007

thomhurst opened this issue Nov 5, 2024 · 7 comments · Fixed by #4041
Assignees
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library In-PR

Comments

@thomhurst
Copy link
Contributor

thomhurst commented Nov 5, 2024

Based on this discussion: #3991

A few things:

  • Currently a framework author would have to know about a specific traits key that needs adding to the PropertyBag - Leaking internal testing platform implementation details and could be easily missed or unknown. This could be abstracted away behind a custom property object.
  • Authors would also need to know how Categories are defined vs Traits. (Seems to be the category is a key with no value, and a trait is a key value pair)
  • SerializableNamedKeyValuePairsStringProperty which the VSTest bridge uses is internal, so framework authors don't have the option of using that.

Suggestion:

public sealed record TestTraitsProperty(
        IEnumerable<string> Categories,
        IEnumerable<KeyValuePair<string, string>> Traits) : SerializableNamedKeyValuePairsStringProperty("traits",
    [
        ..Categories.Select(category => new KeyValuePair<string, string>(category, string.Empty)),
        ..Traits
    ]);
@thomhurst
Copy link
Contributor Author

Even without this, there is still the issue they the underlying property type is internal. I think this is blocking framework authors from setting traits/categories unless there's a workaround?

@Evangelink
Copy link
Member

Marking as bug although I don't have time to test/investigate right now. We should have supprot for traits/properties/metadata as it's a heavily used feature in VS.

@Evangelink Evangelink added Type: Bug Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library External: Test Explorer and removed Needs: Triage 🔍 labels Nov 11, 2024
@Evangelink
Copy link
Member

It's probably a better idea that exposing this technical type, let me discuss with the team and get back to you.

@Evangelink Evangelink changed the title [Testing Platform] TestTraitsProperty Add traits to a TestNode properties Nov 11, 2024
@Evangelink Evangelink added Type: Feature and removed Type: Bug External: Test Explorer Type: Feature Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library labels Nov 11, 2024
@Evangelink
Copy link
Member

Hey @thomhurst,

Good news, I was doing some checks and tests about this and found out we already implemented TestMetadataProperty, it's public and it's already plugged into the communication protocol for Test Explorer.

I'll close as done but please if there are any bug please reopen/comment.

@thomhurst
Copy link
Contributor Author

So for a category do I just add a metadata property with an empty key?

@Evangelink
Copy link
Member

Evangelink commented Nov 11, 2024

Null or empty string value, the category is the key. I guess we could provide a different ctor for that!

See https://github.com/microsoft/testfx/blob/main/docs/mstest-runner-protocol/001-protocol-intro.md

// Key value pairs of traits. Traits have name and value. Frameworks that only support categories,
// can leave the value null, or empty.
// Example: "traits": [{ "trait1": "traitValue1"}, {"trait2": "traitValue2" }, { "category1": null }]
'traits': Trait[];

@Evangelink Evangelink reopened this Nov 11, 2024
@Evangelink Evangelink added this to the MSTest 3.7 / Platform 1.5 milestone Nov 11, 2024
@thomhurst
Copy link
Contributor Author

Thanks seems to be working great. Up to you if you want to leave this open to create a simpler constructor 😄

@Evangelink Evangelink self-assigned this Nov 12, 2024
@Evangelink Evangelink added the Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library In-PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants