Skip to content

Changes to TheoryData break tests with arrays of objects #3031

@MattVane

Description

@MattVane

After today's upgrade to xUnit 2.9.1 we've found an issue with tests that are parameterized by arrays of objects e.g.

[Theory]
  [MemberData(nameof(ExampleParameters))]
  public void ExampleParameterizedTestMethod(string[] values)
  {
      Assert.All(values, s => Assert.True(s.Length < 10));
  }

  public static TheoryData<string[]> ExampleParameters =>
      new TheoryData<string[]>
      {
          { new string[] { "0", "2", "4" } },
          { new string[] { "0", "8", "6" } }
      };

This code consistently fails with "Test method expected 1 parameter value but n parameter values were provided" as if it interpreting the array as a set of parameters instead of a single parameter.

Release notes state "any code that was previously depending on it returning IEnumerable<object[]> may need to be rewritten (i.e., casting the data to IEnumerable<object[]> explicitly before enumerating)." but I honestly don't see where I could be explicitly casting/specifying the types any more?

When T is a primitive (e.g. int) everything seems to work okay, but not so much with objects.

It doesn't seem to fail if we use List instead of T[] so we have a workaround for now, but I thought you guys should be aware

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA fault in an existing featureCore frameworkxunit.v3.core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions