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
Problem Statement
Currently, when using Method Data Sources, you can return an
IEnumerable<Func<(int, int, int)>>orIEnumerable<Func<CustomTestDataClass>>and a test method consumes it by ingesting the data through the parameter (i.e.TestMethod(int a, int b, int c)orTestMethod(CustomTestDataClass data)) with no issue.However, when using this with
IEnumerable<TestDataRow<(int, int, int)>>, you must consume it byTestMethod(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 parameterizedDisplayNameof theTestDataRow, 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:
Then use it in the test method like:
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 = $arg3Feature 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:
Obviously, this test data is over simplified, but you could have very complex data setup and still utilize the parameterized
DisplayName.Contribution