Skip to content

Overloaded [Test] methods in a generic class: both are discovered, only one runs #7207

Open

Description

@thomhurst

What happens

Two [Test] methods in a generic test class that overload one name are both discovered, but only one of them runs. This happens in both source-generated and reflection modes.

[Arguments(1)]
public class GenericClassOverloadTests<T>(T value)
{
    [Test]
    [Arguments("a", 3)]
    public async Task Overloaded(string first, int other = 7) { /* ... */ }

    [Test]
    [Arguments("a", "b")]
    public async Task Overloaded(string first, string other = "x") { /* ... */ }
}

With these in tests/TUnit.TestProject (on the #7199 branch, which also merges #7148), I saw the following:

  • --list-tests shows both Overloaded(a, 3) and Overloaded(a, b).
  • A run with --treenode-filter "/*/<namespace>/*/*" reports one fewer test than discovery, and only Overloaded(a, 3) appears among the results. Both modes behave the same.

Suspected cause

The test id (TestIdentifierService.GenerateTestId) includes the method's parameter types. So the two tests most likely end up with the same MethodMetadata.Parameters and therefore the same id, and one of them is then deduplicated. For a generic class, parameter metadata is looked up by method name (ParameterMetadataFactory.ForGenericMethod(type, name, ...)), which could resolve to the first overload. I have not checked whether a non-generic class behaves the same way.

Expected

Both overloads run and report separately, with distinct test ids.

Found while adding fixtures for #7199.

Activity

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