JetBrains / TeamCity.VSTest.TestAdapter

Apache License 2.0
30 stars 14 forks source link

Unable to retrieve test parameters from parameterized xunit tests #46

Open NikolayPianikov opened 8 months ago

NikolayPianikov commented 8 months ago

xunit works correctly when the test parameter has a primitive type - string, int, etc. These parameters are displayed in the displayName attribute:

[Theory]
    [MemberData(nameof(GetParameters1))]
    public void Parametrized1(string param1, int param2)
    {
    }

    public static IEnumerable<object[]> GetParameters1()
    {
        for (var i = 0; i < 1; i++)
        {
            yield return new object[]
            {
                $"Abc {i}",
                i
            };
        }
    }

image

If at least one of the attributes is not of primitive type, all parameters disappear from displayName:

[Theory]
    [MemberData(nameof(GetParameters2))]
    public void Parametrized2(string param1, int param2, IReadOnlyCollection<Data2> param3)
    {
    }

    public static IEnumerable<object[]> GetParameters2()
    {
        for (var i = 0; i < 1; i++)
        {
            yield return new object[]
            {
                $"Abc {i}",
                i,
                ImmutableArray.Create(
                    new Data2("str 1", 33),
                    new Data2("str 2", 99))
            };
        }
    }

    public record Data2(string StrVal, double DoubleVal);

image

It would be useful to add a resultDisplayName attribute that contains the correct value - with all parameters. For example, this is necessary for correct generation of allure test reports

flakey-bit commented 1 month ago

This also means the test counts are wrong in some cases.

If you want to fix test counts once and for all, surely it should be tied to the test ID rather than tricks with the display name