Skip to content

[Bug]: xUnit TheoryData<T, U> doesn't translate into compilable code #5000

Description

@Cheesebaron

Description

While using TUnitMigrator I encountered an issue when using TheoryData<T1, T2> with multiple types it translates into an IEnumerable<T1, T2> and leads to code that cannot compile.

Given you have a xUnit Theory with TheoryData like so:

[Theory][MemberData(nameof(MyData))]publicvoidMyTest(stringa,intb){}

and the data defined as:

publicstaticTheoryData<string,int>MyData{get{vardata=newTheoryData<string,int>{{"a",1},{"b",2}};returndata;}}

Then when the TheoryData gets transformed into a MethodDataSource it seems to create an IEnumerable<string, int>, but the data variable is transformed into an array with only the first type like:

publicstaticIEnumerable<string,int>MyData{get{vardata=string[]{{"a",1},{"b",2}}}}

This doesn't compile at all.

Expected Behavior

I would have expected the analyzer to generate something like follows or similar that would compile and work with data driven test cases:

publicstaticIEnumerable<Func<(string,int)>>MyData{get{yieldreturn()=>("a",1);yieldreturn()=>("b",2);}}

Actual Behavior

Code not compiling

Steps to Reproduce

  1. Clone: https://github.com/Cheesebaron/tunitmigrator-xunittheorydata-repro
  2. dotnet tool install --global TUnitMigrator
  3. tunit-migrate /path/to/tunitmigrator-xunittheorydata-repro

TUnit Version

1.16.4

.NET Version

.NET 10

Operating System

macOS

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions