Skip to content

Conversation

@delatrie
Copy link
Contributor

@delatrie delatrie commented Aug 8, 2025

Context

Both NUnit and xUnit allow for generic test methods:

public class TestClass
{
    [TestCase(1)] // T is System.Int32
    [TestCase("a")] // T is System.String
    public void TestMethod<T>(T arg)
    {
        /// ...
    }
}

Currently, Allure NUnit and Allure xUnit.net include the type argument (i.e., System.Int32 or System.String) in fullName.

Mapping issues

Having fullName depending on method type arguments leads to a single test method having different fullName (and, consequently, testCaseId) values depending on the types of its arguments. That maps different argument sets of the test method into separate test cases in TestOps, rather than a single test case that encompasses all argument sets.

Additionally, this makes the selective run feature trickier to use, as all combinations of argument types need to be known in advance.

Those issues become more annoying in case the argument types can change across runs, e.g., if the values are provided from the outside.

While not significantly affecting Allure 2, these issues will become apparent in Allure 3, where plans are underway to rework how parameterized tests are reported.

fullName size issue

In most cases, type arguments are much more verbose than their corresponding type parameters. Some examples:

Constructed method Type parameter Type argument
TestClass.TestMethod(1) T System.Int32
TestClass.TestMethod("a") T System.String
TestClass.TestMethod(new List()) T System.Collections.Generic.List`1[System.String]
TestClass.TestMethod(new MyClass()) T MyAssemblyName:MyNamespace.MyClass

The proposal

This PR changes the fullName calculation to be based on generic method definitions instead of constructed generic methods. That replaces all method type arguments with their parameters in fullName.

Note

Only method type arguments are replaced with their parameters. If the method is defined in a generic type, the fullName continues including the type arguments of that type. That's because multiple instantiations of the generic type create practically different types with different methods that must each correspond to its own test case.
That said, defining test methods in a generic test class is a niche use unique to NUnit. xUnit doesn't support parameterization at the class level and thus doesn't support generic test classes.

The fix doesn't affect non-generic methods.

Checklist

If a method is a constructed generic method (like Class.Method<int>()),
its fullName is now calculated based on its generic definition.
That makes fullNames independent of type arguments (i.e., on concrete types).
@delatrie delatrie added the type:bug Something isn't working label Aug 8, 2025
@delatrie delatrie merged commit 25676e9 into main Aug 8, 2025
7 checks passed
@delatrie delatrie deleted the fix/fullNames-of-generic-methods branch August 8, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:core type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants