Skip to content

TUnit0001 rejects MethodDataSource Arguments that omit optional parameters #7418

Closed

Description

@thomhurst

Summary

TUnit0001 rejects a MethodDataSource call that omits an optional data-method parameter. Execution supports optional defaults, but reflection overload selection also needs the separate fix in #7331 (open PR #7421). Users must suppress the analyzer even for supported calls; analyzer validation should agree with the execution overload rules.

Reproduction

public static IEnumerable<string> Rows(string text, int count = 1) => [text];

[Test]
[MethodDataSource(nameof(Rows), Arguments = new object[] { "a" })]
public void Test(string value) { }

Build with the analyzer enabled. TestDataAnalyzer selects methods by exact argument count (or by removing CancellationToken), without accounting for optional parameters.

Expected and actual

Expected: accept the omitted optional parameter and select the same overload as execution. Actual: TUnit0001 requires the missing argument. Add coverage for overloaded methods and defaults on overrides as well.

Environment

Observed in TUnit main at ca4437c and the existing optional-argument parity tests, which suppress TUnit0001. Runtime fix tracked by #7331; this issue covers analyzer validation separately.

Acceptance criteria

Please allow omitted optional data-method parameters in TUnit0001 validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions