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

Records with default constructor not shown as single tests #1767

Closed
wondering639 opened this issue Nov 4, 2023 · 2 comments
Closed

Records with default constructor not shown as single tests #1767

wondering639 opened this issue Nov 4, 2023 · 2 comments

Comments

@wondering639
Copy link

wondering639 commented Nov 4, 2023

Describe the bug

I would expect this to create three single entries in the Test Explorer, but it does not (-> you can not repeat a single test, only all three):

public record CustomRecord(
    decimal Number, 
    string Comment
);

public static IEnumerable<object[]> RecordTestData
{
    get
    {
        yield return new object[] {
            new CustomRecord(1m, "first")
        };

        yield return new object[] {
            new CustomRecord(2m, "second")

        };

        yield return new object[] {
            new CustomRecord(3m, "third")
        };
    }
}

[TestMethod]
[DynamicData(nameof(RecordTestData))]
public void TestWithRecordTestData(CustomRecord item)
{
    Console.WriteLine($"item number is {item.Number} entries");
}

In this case, no "subentries" are created in the Test Explorer (you can see that as the triangle on the left side is not there):
image

However it works when using

public record CustomRecord
{
    public decimal Number;
    public string Comment = "";
}

instead of

// I call this record constructor variant
public record CustomRecord(
    decimal Number, 
    string Comment
);

See how we suddenly have three single entries in the Test Explorer:
image

Steps To Reproduce

see bug description

Expected behavior

  • all tests shown as single entries
  • both record "variants" (constructor and property "variant") should yield the same output in Test Explorer

Actual behavior

all tests shown as one entry when using record constructor variant

@Evangelink
Copy link
Member

Hi @wondering639,

This issue is related to #1462. MSTest is currently relying on datacontract serializer as a way to discriminate entries. Because of that some data types are not "supported". We know how painful this is but we are really limited by the design of vstest in fixing this issue.

@Evangelink
Copy link
Member

Closing this one, you can follow #1462 to get a notification about when the fix will be available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants