Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link

Description

@ska737
Issue body actions

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
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.