xunit / visualstudio.xunit

VSTest runner for xUnit.net (for Visual Studio Test Explorer and dotnet test)
https://xunit.net/
Other
144 stars 81 forks source link

[Bug] test explorer doesn't correctly display test cases from MemberData for valuetuples/objects #405

Closed kicsiede closed 5 months ago

kicsiede commented 5 months ago

test explorer doesn't correctly display test cases from MemberData for valuetuples/objects. i would expect to see all cases for valuetuples as well in the tree, consistently with the simpler case. (all tests are run actually, in the result summary window you see 3 results for the node) with the following code you can see the difference:

[Theory, MemberData(nameof(Ints))]
public void MultipleCasesShowUp(int _)
{
}
public static object[][] Ints =>
[
    [1],
    [2],
    [3]
];

[Theory, MemberData(nameof(Tuples))]
public void SingleCaseShowsUp_WithMultipleResults((int, int) _)
{
}

public static object[][] Tuples =>
[
    [(1, 1)],
    [(2, 2)],
    [(3, 3)]
];
bradwilson commented 5 months ago

This isn't a bug, this is how the system treats values that aren't serializable. Tuples are not currently serializable in v2.

kicsiede commented 5 months ago

i'm not sure what system you refer to here exactly, but in the results window it is clearly visible that the arguments can be (are) resolved correctly (afaik both Tuple<> and ValueTuple<> are serializable):

Results

    1)   XUnitProba.Class1.SingleCaseShowsUp_WithMultipleResults(_: Tuple (1, 1)) 
      Duration: < 1 ms

    2)   XUnitProba.Class1.SingleCaseShowsUp_WithMultipleResults(_: Tuple (2, 2)) 
      Duration: < 1 ms

    3)   XUnitProba.Class1.SingleCaseShowsUp_WithMultipleResults(_: Tuple (3, 3)) 
      Duration: < 1 ms

nevertheless this is definitely unexpected behavior imho, and should be remedied somehow

bradwilson commented 5 months ago

Printing arguments in results is not the same as serializability.

The long answer: The design of the Visual Studio test runner (at least as it stands today) is that it spins up one process and asks the test framework to enumerate the tests. It then takes that enumerated information, and passes that to a second process where the tests are run. In order for us to be able to run an individual item in a data-driven test, the data itself must be serializable in order to be able to be sent across those two processes. The VSTest system requires that we serialize everything that is required to run a test, so that they can hand that serialization back to us and we can run it.

We can serialize a fixed set of things on our own, and then we rely on developers who want to be able to run their individual data items to provide their own serialization for anything that we don't support. Tuples aren't in the built-in support list.

My recommended work around is: Don't use tuples. Just pass the values individually instead.