Skip to content

Visual Studio 2022: Test Explorer duplicates each Test with concatenated Namespace #5928

Closed

Description

@Lorilatschki

Describe the bug

When hosting tests in net8.0 using the latest MTP version 1.7.3, each test is shown twice inside the Test Explorer in Visual Studio 2022

Steps To Reproduce

Provide the steps to reproduce the behavior:

  1. Open the repository TestExplorerIssue in VS 2022
  2. Compile the whole solution
  3. Open the Test Explorer
  4. Each test is shown twice with a concatenated namespace

Expected behavior

Each test is only shown once.

Actual behavior

Each test is shown twice.

Image

Additional context

With version <= v1.6.3 of MTP the issue does not exist.
When using nunit with version 4.3.2 the issue does not exist. So this might be a related to xunit.v3, however, the fact that it worked with MTP <= v1.6.3 indicates that something has changed under the hood within the Microsoft Testing Platform.

Activity

  1. Youssef1313 commented on Jul 2, 2025

    @Youssef1313
    Member

    I'm not able to reproduce it so far, but I'm suspecting it's related to this option:

    Image

    Can you verify if it's turned on or off for you? And try to turn it off if it's on?

    Also can you please try the latest xunit.v3 prerelease?

  2. Lorilatschki commented on Jul 2, 2025

    @Lorilatschki
    Author

    Thanks for the very fast reply. The setting is turned on

    Image

    I have turned off the setting, when doing so, the issue disappears.

    With discover tests in real time on and the latest pre-release of xunit.v3 version v3.0.0-pre.25 the issue also disappears.

  3. Youssef1313 commented on Jul 2, 2025

    @Youssef1313
    Member

    Thanks for confirmation Lori (@Lorilatschki). This is related to the change we had to take in #5409 which affected xUnit. To give a bit of history, we have had TestMethodIdentifierProperty class with Namespace and TypeName property. The API was intended to be used that Namespace is just the namespace part, and TypeName is just the type name without the namespace.

    In the Json RPC protocol that we use to communicate with Visual Studio, we translated Namespace to location.namespace and TypeName to location.type. However, the assumption on Test Explorer side was unfortunate and we couldn't change it. It assumed that location.type will also contain the namespace.

    As a result, we have had a discrepancy in assumptions in MTP and VS. Moreover, xUnit was including the namespace as part of TypeName (which wasn't how our public API is intended to be used), and that's where the namespace duplicated come from.

    When we aligned MTP with Test Explorer, this unfortunately broke xUnit, but for a good reason, because again, TypeName isn't intended to include the namespace.

    The real-time discovery is out of all this, and in this case it has the right namespace and type name. But what the test project sends later to TE is the test cases with the duplicated namespace. And Test Explorer doesn't seem to be capable of throwing away the real-time discovery results and instead merges the two results together, causing this behavior.

    The newer version of xunit.v3 handles TestMethodIdentifierProperty correctly, so the actual discovery is now aligned again with real-time discovery and they produce the same results, causing the issue to go away.

    I know this might be too much information, but I wanted to give a bit of history.

    The short answer is, I would consider the current stable version of xunit.v3 (2.0.3 at the moment) as not compatible with MTP 1.7+.
    So, if you use xunit.v3 2.0.3, stick with MTP 1.6. If you are okay using a prerelease of xunit.v3, then you can use MTP 1.7+.

    I'm going to close then as there is unfortunately not much to do on our side.

  4. removed
    needs/triage
    on Jul 2, 2025
  5. Lorilatschki commented on Jul 2, 2025

    @Lorilatschki
    Author

    Youssef Fahmy (@Youssef1313) thanks a lot for the detailed information. That helped a lot to understand the root cause. I have closed the 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions