Skip to content

Add traits to a TestNode properties #4007

Closed

Description

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
    ]);

Activity

  1. thomhurst commented on Nov 7, 2024

    @thomhurst
    ContributorAuthor

    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?

  2. Evangelink commented on Nov 11, 2024

    @Evangelink
    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.

  3. added
    area/mtp
    external/test-explorer
    and removed
    needs/triage
    on Nov 11, 2024
  4. Evangelink commented on Nov 11, 2024

    @Evangelink
    Member

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

  5. changed the title [-][Testing Platform] TestTraitsProperty[/-] [+]Add traits to a TestNode properties[/+] on Nov 11, 2024
  6. added and removed
    external/test-explorer
    area/mtp
    on Nov 11, 2024
  7. Evangelink commented on Nov 11, 2024

    @Evangelink
    Member

    Hey Tom Longhurst (@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.

  8. thomhurst commented on Nov 11, 2024

    @thomhurst
    ContributorAuthor

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

  9. Evangelink commented on Nov 11, 2024

    @Evangelink
    Member

    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[];

  10. thomhurst commented on Nov 11, 2024

    @thomhurst
    ContributorAuthor

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

  11. added
    area/mtp
    on Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/mtpstate/in-pr

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions