Skip to content

feat: auto-infer [CombinedDataSources] for single-parameter methods #4766

@thomhurst

Description

@thomhurst

Problem

When a test method has a single parameter with a data source attribute, [CombinedDataSources] is still required:

[Test]
[CombinedDataSources] // seems redundant for a single parameter
public async Task Unauthenticated_Requests_Are_Rejected(
    [ClassDataSource<ApiClientFixture>(Shared = SharedType.PerTestSession)]
    ApiClientFixture client)
{
    var response = await client.Client.GetAsync("/api/orders/mine");
    await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.Unauthorized);
}

Without it, you get TUnit0070 and TUnit0038 errors.

Proposed Behavior

When a method has exactly one parameter with a data source attribute, TUnit could automatically treat it as a combined data source (there's nothing to combine - it's just a single source). The [CombinedDataSources] attribute would only be strictly required when there are 2+ parameters with data source attributes.

Alternatively, this could be its own attribute concept - something like parameter-level [ClassDataSource] being allowed without [CombinedDataSources] when there's only one parameter.

Context

Discovered while building the CloudShop Aspire + TUnit example (#4761). The AuthorizationTests class had a simple single-parameter test that required the extra attribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions