Skip to content

[Feature]: Method Data Source: Match functionality of IEnumerable<TestDataRow<Func<>>> with IEnumerable<Func<>> #6161

Closed

Description

@ska737

Problem Statement

Currently, when using Method Data Sources, you can return an IEnumerable<Func<(int, int, int)>> or IEnumerable<Func<CustomTestDataClass>> and a test method consumes it by ingesting the data through the parameter (i.e. TestMethod(int a, int b, int c) or TestMethod(CustomTestDataClass data)) with no issue.

However, when using this with IEnumerable<TestDataRow<(int, int, int)>>, you must consume it by TestMethod(Func<(int, int, int)> dataFunction). This is fine when running the tests, you just have to assign the result of invoking the function. The issue is when using the parameterized DisplayName of the TestDataRow, the parameters do not match, since the parameter is the function.

Proposed Solution

I would like to be able to define the data source as:

public static IEnumerable<TestDataRow<Func<(int, int, int)>> TestDataMethod()
{
    yield return new(
        () =>
        {
            return (1, 1, 2);
        },
        DisplayName: "$arg1 + $arg2 = $arg3"
    );
}

Then use it in the test method like:

[Test]
[MethoDataSource(typeof(TestDataSources), typeof(TestDataSources.TestDataMethod))]
public async Task TestMethod(int a, int b, int c)
{
    ...
}

With the test display being 1 + 1 = 2.

Alternatives Considered

There is no workaround. I am using it as if it would work correctly, and living with the DisplayName being: $arg1 + $arg2 = $arg3

Feature Category

Data-Driven Testing (Arguments, DataSources)

How important is this feature to you?

Nice to have - would improve my experience

Additional Context

Doing this would allow a person to define a single, parameterized, display name for multiple test cases. Take for example:

public static IEnumerable<TestDataRow<Func<(int First, int Second, int Expected)>> TestData()
{
    string displayName = "$First + $Second = $Expected";
    yield return new(
        () =>
        {
            return (1, 1, 2);
        },
        DisplayName: displayName);
    yield return new(
        () =>
        {
            return (1, 2, 3);
        },
        DisplayName: displayName);
}

Obviously, this test data is over simplified, but you could have very complex data setup and still utilize the parameterized DisplayName.

Contribution

  • I'm willing to submit a pull request for this feature

Activity

  1. added
    enhancement
    on Jun 5, 2026
  2. ska737 commented on Jun 5, 2026

    @ska737
    Author

    Actually, while writing more test cases, the current implementation does pose a problem. Since the DisplayName does not replace the parameters, the test runner believes they are the same tests, and runs the first one as many times as the DisplayName is the same.

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

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions