Skip to content

[Arguments] row that breaks a constraint is reported in source-gen mode but silently dropped in reflection mode when the method has [GenerateGenericTest] #7153

Closed

Description

@thomhurst

Summary

When a generic test method has a method-level [GenerateGenericTest], an [Arguments] row whose inferred type argument breaks the method's constraints behaves differently in the two modes:

  • Source-gen mode: the row is reported as a failed test (Type 'String' does not satisfy the 'struct' constraint for generic parameter 'T').
  • Reflection mode: the row is silently dropped. ReflectionTestDataCollector.InferMethodInstantiationsFromDataSources skips sources whose inferred types break the constraints, and the row does not appear as a test at all.

Repro

public class GgtArgsTests
{
    [Test]
    [GenerateGenericTest(typeof(int))]
    [Arguments("x")]
    [Arguments(5)]
    public void Run<T>(T value) where T : struct { }
}

TUnit.TestProject, net10.0, with a treenode filter on this class:

  • Source-gen: 2 tests. Run<int>(5) passes, Run fails with the struct constraint message.
  • --reflection: 1 test. Run<int>(5) passes, and the "x" row is gone.

(TUnit0001 flags "x" at compile time, so the repro needs #pragma warning disable TUnit0001.)

Expected

The same tests in both modes. After #7097 / #7107 the convention is that an invalid row is reported, not dropped, so reflection mode should probably report it as source-gen mode does.

Context

Found while fixing #7116. That PR aligns the [MethodDataSource] / typed-data-source case with [GenerateGenericTest] (source-gen no longer reports a data source whose declared type breaks the constraint, because the rows run on the [GenerateGenericTest] type, as in reflection mode). It leaves [Arguments] rows alone, because a literal argument cannot be converted to the listed type the way a broad declared type can.

Activity

  1. added a commit that references this issue on Oct 20, 2026
    45b4c90
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