Skip to content

Test class name missing in TRX report for parametrized fixture when running through MTP #1351

Closed

Description

@radim-bernatik-veeam

In the following example is situation, when class name is not fully included in resulting TRX report. Only the namespace of the class is included, but the class name is missing. There are newest packages for MTP (2.0.1) and NUnit3TestAdapter (6.0.0-beta.1). But the problem was firstly recognized by me on MTP/1.8.1 and NUnit3TestAdapter/5.0.1. I also checked NET 8 and NET 10 rc1 frameworks, issue is reproducible on both.

In the TRX report for both instances of the Test1 test is only className="One", when running using MTP.
The TRX report fragment:

    <UnitTest name="Test1" storage="d:\git\mtp\one\bin\debug\net10.0\one.dll" id="f250b33b-8a35-b41a-e7bf-8e9547f93a26">
      <Execution id="983facad-df20-4239-a725-afd3d6150424" />
      <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net10.0\One.dll" adapterTypeName="executor://NUnitExtension/1.0.0+c7d97261880dc4b9bcf3f48c2cabc5293016adba" className="One" name="Test1" />
    </UnitTest>

Execution command: dotnet exec One\bin\Debug\net10.0\One.dll --results-directory TestResults --report-trx

On the other side, when same example is executed by vstest.console.exe command, the TRX report contains proper className="One.Tests(One)" and className="One.Tests(Two)".
The TRX report fragment:

  <TestDefinitions>
    <UnitTest name="Test1" storage="d:\git\mtp\one\bin\debug\net10.0\one.dll" id="31e09d51-24f9-f1bf-3546-ea0d27e9d1e2">
      <Execution id="205cb3bb-29b2-47ff-8f7a-16721f04c50a" />
      <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net10.0\One.dll" adapterTypeName="executor://nunit3testexecutor/" className="One.Tests(One)" name="Test1" />
    </UnitTest>
    <UnitTest name="Test1" storage="d:\git\mtp\one\bin\debug\net10.0\one.dll" id="b28b10d5-d1e1-b8e3-f896-8c4751d57b96">
      <Execution id="8cd2ab2d-6490-4b08-8438-500a777931a3" />
      <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net10.0\One.dll" adapterTypeName="executor://nunit3testexecutor/" className="One.Tests(Two)" name="Test1" />
    </UnitTest>
  </TestDefinitions>

Execution command: vstest.console.exe One\bin\Debug\net10.0\One.dll /logger:trx

In the example code bellow there are two TestFixtureData provider methods, one with used SetArgDisplayNames method, and one without. Reports above are from usage the one with custom test data names GetTestCasesWithNames. But this has no impact on the results. Even if test data contains custom name or not, or even if TestFixture attributes is used directly with parameters, in all cases the .Tests(One) or .Tests(1) is missing from the TRX report's TestMethod node className attribute value (when MTP is used, old vstest.console.exe runner works without issues in all cases).

I don't know if this issue is in MTP or NUnit3TestAdapter code, but I guess the NUnit3TestAdapter one, because the strange behavior is triggered by usage of parametrized fixture attributes.

I think this issue is quite critical, because it prevents usage of parametrized fixtures in MTP. When class name is not fully recognized in TRX report, we cannot map the test result to proper source file and address possible issues. It also leads to test method name misidentification because the class name is missing from the full tests name. It is nowhere in TRX report.

Example unit test class - UnitTest1.cs

using NUnit.Framework;
using System.Collections;

namespace One
{
    //[TestFixture(1)]
    //[TestFixture(2)]
    //[TestFixtureSource(nameof(GetTestCases))]
    [TestFixtureSource(nameof(GetTestCasesWithNames))]
    public class Tests
    {
        private int _counter;

        public Tests(int counter)
        {
            _counter = counter;
        }

        [Test]
        public void Test1()
        {
            Console.WriteLine($"Test1:{_counter}");
            Assert.Pass();
        }

        private static IEnumerable<TestFixtureData> GetTestCases()
        {
            yield return new TestFixtureData(1);
            yield return new TestFixtureData(2);
        }

        private static IEnumerable<TestFixtureData> GetTestCasesWithNames()
        {
            yield return new TestFixtureData(1).SetArgDisplayNames("One");
            yield return new TestFixtureData(2).SetArgDisplayNames("Two");
        }
    }
}

Example project file - One.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <EnableNUnitRunner>true</EnableNUnitRunner>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit.Analyzers" Version="3.8.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="6.0.0-beta.1" />
    <PackageReference Include="Microsoft.Testing.Extensions.Telemetry" Version="2.0.1" />
    <PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="2.0.1" />
    <PackageReference Include="Microsoft.Testing.Extensions.VSTestBridge" Version="2.0.1" />
    <PackageReference Include="Microsoft.Testing.Platform" Version="2.0.1" />
    <PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="2.0.1" />
  </ItemGroup>
</Project>

Activity

  1. OsirisTerje commented on Nov 5, 2025

    @OsirisTerje
    Member

    Can you enable the Dump (runsettings) and look at the results there? If the same results are there, it is in the framework, if it is correct there, it is the adapter.

    https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html#dumpxmltestdiscovery-and-dumpxmltestresults

    Also, if you skip using MTP, does it then work as expected?

    PS:

    On the other side, when same example is executed by vstest.console.exe command, the TRX report contains proper className="One.Tests(One)" and className="One.Tests(Two)".

    This indicates it is related to using MTP at least.

  2. radim-bernatik-veeam commented on Nov 5, 2025

    @radim-bernatik-veeam
    Author

    Here is the output from dump file:

          <test-suite type='TestSuite' id='0-1006' name='One' fullname='One' runstate='Runnable' testcasecount='2'>
             <test-suite type='ParameterizedFixture' id='0-1004' name='Tests' fullname='One.Tests' runstate='Runnable' testcasecount='2'>
                <test-suite type='TestFixture' id='0-1000' name='Tests(One)' fullname='One.Tests(One)' classname='One.Tests' runstate='Runnable' testcasecount='1'>
                   <test-case id='0-1001' name='Test1' fullname='One.Tests(One).Test1' methodname='Test1' classname='One.Tests' runstate='Runnable' seed='1839287280' />
                </test-suite>
                <test-suite type='TestFixture' id='0-1002' name='Tests(Two)' fullname='One.Tests(Two)' classname='One.Tests' runstate='Runnable' testcasecount='1'>
                   <test-case id='0-1003' name='Test1' fullname='One.Tests(Two).Test1' methodname='Test1' classname='One.Tests' runstate='Runnable' seed='514243834' />
                </test-suite>
             </test-suite>
          </test-suite>
    

    Looks like the information is in the dump in correct form fullname='One.Tests(One).Test1', classname='One.Tests'. But I am not export on the dump file format, I used it for the first time now.

    Also, if you skip using MTP, does it then work as expected?

    What do you exactly mean by this? Isn't running using vstest.console.exe enough? When running through vstest.console, the TRX report contain correct values for parametrized fixture.

  3. added
    MTP
    on Nov 5, 2025
  4. OsirisTerje commented on Nov 5, 2025

    @OsirisTerje
    Member

    Thanks! The dump information is fine.

    That narrows down the issue to be either in the adapter or in the MTP.

    Isn't running using vstest.console.exe enough?

    It is a strong indication that MTP has something to do with this. But, there are differences between running dotnet test and vstestconsole. You can turn off MTP in the csproj file too, and still use the test explorer and dotnet test.

  5. OsirisTerje commented on Nov 5, 2025

    @OsirisTerje
    Member

    Repro added here: https://github.com/nunit/nunit3-vs-adapter.issues/tree/master/Issue1351 (Thanks for the repro code @radim-bernatik-veeam !)

    @Youssef1313 The dump file have the correct names, and the adapter itself doesn't change the names, it just sends them further.

    I haven't debugged through this yet, but nice if you can comment on whether this can be in the bridge or the mtp itself.

  6. radim-bernatik-veeam commented on Nov 5, 2025

    @radim-bernatik-veeam
    Author

    I have made additional test. Switched to NET 8 (vstest mode is not supported in NET 10 at all), set the <TestingPlatformDotnetTestSupport>false</TestingPlatformDotnetTestSupport> in csproj file and run dotnet test --logger trx command.

    The tests were executed in vstest mode through dotnet test command. Result in TRX is correct. So it is really connected to MTP.

  7. Youssef1313 commented on Nov 5, 2025

    @Youssef1313
    Contributor

    The FQN given to MTP by NUnit is:

    Issue1351.Tests(One).Test1
    

    Is that really expected?

  8. radim-bernatik-veeam commented on Nov 6, 2025

    @radim-bernatik-veeam
    Author

    Yes, I think Issue1351.Tests(One).Test1 is expected. The namespace is Issue1351, class name is Tests, the parameter is given by TestFixtureSource attribute with data from GetTestCasesWithNames function where data are named by SetArgDisplayNames("One"), thus the test class name is expanded by (One). The tests itself is Test1, of course.

    The FQN given to MTP by NUnit is:

    If I understand correctly, the problem is then in MTP, not in NUnit adapter. Am I right?

  9. Youssef1313 commented on Nov 6, 2025

    @Youssef1313
    Contributor

    A FQN isn't supposed to have parameters in the first place. So it's an unexpected NUnit behavior.

    We might consider implementing a workaround for that in VSTestBridge. Such workaround might end up breaking F# scenarios though, where parentheses can be part of identifier names.

  10. OsirisTerje commented on Nov 8, 2025

    @OsirisTerje
    Member

    In NUnit a test may have any name (not quite true, but nearly so), it is not strictly following C# FQN. However, it most cases it does follow the FQN, and most of the variations are like shown above.

    The typical names are like:

    # Case Example C# NUnit Internal FQN
    1 Simple MyTest() MyNamespace.MyClass.MyTest
    2 Nested class Outer.Inner.MyTest() MyNamespace.Outer+Inner.MyTest
    3 Generic class GenericTests<int>.MyTest() MyNamespace.GenericTests<System.Int32>.MyTest
    4 Generic method MyTest<int>() MyNamespace.MyClass.MyTest<System.Int32>
    5 Parameterized test [TestCase(1, "A")] MyNamespace.MyClass.MyTest(1,"A")
    6 Parameterized fixture [TestFixture(42)] MyNamespace.MyFixture(42).MyTest
    7 Generic fixture + parameterized test [TestFixture(typeof(int))][TestCase(1)] MyNamespace.GenericFixture<System.Int32>.MyTest(1)

    So the case above is (6).

    In addition, you can set the name to practically anything you like, but in the most weird cases that will not even pass through the adapter. Only the NUnit.Console and NUnitLite can make sense of those.

  11. Youssef1313 commented on Nov 8, 2025

    @Youssef1313
    Contributor

    This would be resolved if you provide ManagedType/ManagedMethod on your end (#1259). Otherwise, we need some way that let you to provide the bridge with the "correct" class name and method name.

  12. OsirisTerje commented on Nov 8, 2025

    @OsirisTerje
    Member

    What would the ManageType and ManagedMethod be of this: MyNamespace.MyFixture(42).MyTest

  13. Youssef1313 commented on Nov 8, 2025

    @Youssef1313
    Contributor

    It's whatever ManagedNameHelper.GetManagedName returns. You don't need to calculate it yourself.

  14. OsirisTerje commented on Nov 21, 2025

    @OsirisTerje
    Member

    Ok, so we could just add these in the adapter, right ? Not sure why that would help, but whatever.....

  15. 1 remaining item

  16. Youssef1313 commented on Dec 4, 2025

    @Youssef1313
    Contributor

    I'm thinking of considering new VSTestBridge-specific properties for providing this information. See microsoft/testfx#5476. This will still require changes on NUnit side.

  17. radim-bernatik-veeam commented on Apr 1, 2026

    @radim-bernatik-veeam
    Author

    It is 4 months stale, any progress or ETA?

  18. Youssef1313 commented on Apr 1, 2026

    @Youssef1313
    Contributor

    We added new API, VSTestBridgedTestFrameworkBase.AddAdditionalProperties, which allows custom bridged frameworks (e.g, NUnit) to provide additional properties. NUnit might be able to use that to provide TestMethodIdentifierProperty. If NUnit is able to provide TestMethodIdentifierProperty, we can adjust TRX to consider it instead of TrxFullyQualifiedTypeNameProperty. Until TestMethodIdentifierProperty gets added by NUnit, it's NUnit work that needs to be done.

  19. radim-bernatik-veeam commented on Jun 4, 2026

    @radim-bernatik-veeam
    Author

    I see that Prefer setting TrxFullyQualifiedTypeNameProperty per TestMethodIdentifierProperty in microsoft/testfx is merged, but can we start using it?

    Unfortunately the microsoft/testfx repository is quite weird because they are releasing testfx and MTP from the same repo. There are tags for testFX, but no tags for MTP releases. So I can't see if the merged PR is released or not.

    Another issue is the comment from above PR "Once NUnit adds TestMethodIdentifierProperty". I am not able to search any issue or source code in NInit where TestMethodIdentifierProperty is mentioned. So it looks like NUnit does not even know about it.

  20. Youssef1313 commented on Jun 4, 2026

    @Youssef1313
    Contributor

    @radim-bernatik-veeam The above PR you can see it's included in v4.2.1 tag. That corresponds to MTP 2.2.1 as we always ship MSTest 4.x and MTP 2.x together with exactly the same minor and patch versions. So the above PR is already available.

    You can also see MTP changelog here: https://github.com/microsoft/testfx/blob/main/docs/Changelog-Platform.md

  21. Youssef1313 commented on Jun 4, 2026

    @Youssef1313
    Contributor

    Another issue is the comment from above PR "Once NUnit adds TestMethodIdentifierProperty". I am not able to search any issue or source code in NInit where TestMethodIdentifierProperty is mentioned. So it looks like NUnit does not even know about it.

    Yes and that's a problem. NUnit should start creating this property.

  22. added this to the 6.3 milestone on Jun 7, 2026
  23. OsirisTerje commented on Jun 7, 2026

    @OsirisTerje
    Member

    @Youssef1313 @radim-bernatik-veeam

    Pr #1449 is a fix for this. Please review it. I have enclosed the resulting trx file there, please check if it is as expected.

  24. radim-bernatik-veeam commented on Jun 8, 2026

    @radim-bernatik-veeam
    Author

    @OsirisTerje, @Youssef1313

    I did a tests using the branch Issue1351 and the issue is solved only partly. In my tests I used original code which is posted here at the start, NUnit version 4.4.0, MTP version 2.2.3. Executed command dotnet exec One\bin\Debug\net8.0\One.dll --results-directory TestResults --report-trx --report-trx-filename One-bin-Debug-net8.0-One.trx --ignore-exit-code 8 --output Detailed --no-ansi.

    In the generated TRX report for NUnitTestAdapter version 6.2.0 (latest nuget) we can see that class name is invalid (of course, no fix is there):

    <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net8.0\One.dll" adapterTypeName="executor://NUnitExtension/1.0.0+4699e8d5aff414161ac15453667bdae4d499565f" className="One" name="Test1" />
    ...
    <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net8.0\One.dll" adapterTypeName="executor://NUnitExtension/1.0.0+4699e8d5aff414161ac15453667bdae4d499565f" className="One" name="Test1" />
    

    When I replaced NUnit3.TestAdapter.dll with the one from the branch, className attribute value changed and now includes the class name with namespace (One.Tests) and not only namespace like the version before fix (One). But still it does not include the parametrized part.

    <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net8.0\One.dll" adapterTypeName="executor://NUnitExtension/1.0.0+75139804895fc04880a9185ae9226682df2c9b61" className="One.Tests" name="Test1" />
    ...
    <TestMethod codeBase="D:\Git\MTP\One\bin\Debug\net8.0\One.dll" adapterTypeName="executor://NUnitExtension/1.0.0+75139804895fc04880a9185ae9226682df2c9b61" className="One.Tests" name="Test1" />
    

    The final solution (maybe once NUnit do its part?) should be className="One.Tests(One)" and className="One.Tests(Two)".

    You can ignore the invalid adapter version (1.0.0+4699e8d5aff414161ac15453667bdae4d499565f) for 6.2.0 in the arapterTypeName property. I have already created separate issue for this. I won't link it here, because it is not related to current one.

  25. OsirisTerje commented on Jun 9, 2026

    @OsirisTerje
    Member

    @radim-bernatik-veeam Good point. Have added parameters to the MTP property. Please check now.

    PS_ Copied your cases into the repro code at Issue1351 in the repro repo for the adapter.

  26. radim-bernatik-veeam commented on Jun 10, 2026

    @radim-bernatik-veeam
    Author

    @OsirisTerje

    I have tested the new version from branch and it looks good. Named parameters works, also automatic names using argument values works as well.

    I consider this fix in the branch as the one which is fixing this issue.

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

    MTPis:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions