Skip to content

Source-gen silently drops a generic test method when its type arguments cannot be inferred from the data source #7163

Closed

Description

@thomhurst

Follow-up split out of #7108 and PR #7143.

What happens

In source-generated mode, a generic test method whose type arguments cannot be inferred at compile time is dropped silently. No test is registered and no diagnostic is reported. Reflection mode still discovers and runs the test, so the two modes disagree on the test count without any hint. Typical inputs:

PR #7143 widened the row shapes source-gen can infer from, but these cases still fall through InferTypesFromMethodDataSource (src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs), which returns null, and no entry is emitted.

How to reproduce

public class Repro
{
    public static IEnumerable<object> Rows() { yield return 1; }

    [Test, MethodDataSource(nameof(Rows))]
    public void Generic<T>(T value) { }
}

dotnet run shows no test. dotnet run -- --reflection shows Generic<int>.

Expected

The issue author asked for one of two things, and this tracks that remaining part of #7108. Either source-gen reports a diagnostic, for example "cannot infer type arguments for generic test X from data source Y; add [GenerateGenericTest] or type the data source", or it emits a placeholder that fails at runtime with that message. Either way, the test must not vanish silently.

Activity

  1. added 3 commits that reference this issue on Oct 20, 2026
    8335281
    d265b7d
    13cebc9
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions