Skip to content

[Bug]: Run Test (by name) in VS fails when test is in a nested class #4144

@AArnott

Description

@AArnott

Description

When the editor is open and caret positioned within a TUnit test, I can typically right-click within the test and invoke the "Run Tests" command (or press Ctrl+R, T) and the test will build and run, showing results via Test Explorer.

But when that test method is within a nested class, an error occurs before the test is executed.

Expected Behavior

I expect the test to execute like any other test in a non-nested class would.

Actual Behavior

The Output tool window's Tests pane shows this output after a failure:

Building Test Projects
Executing test method: EnumTests+EnumAsStringTests.UnrecognizedName
Not all tests from the test run selection could be discovered.
========== Starting test run ==========
========== Test run aborted: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========

Steps to Reproduce

Create a test class with:

public partial class NativeAOTTests
{
	[Test]
	public void Outer()
	{
	}

	public class Nested
	{
		[Test]
		public void Inner()
		{
		}
	}
}

Right-click within the Outer() method and click the Run Tests command from the context menu.
It runs.

Now do the same for the Inner() method. Notice how it fails.

You can also try the command from the class declaration itself (i.e. within the class, but not within a test method). It works for the outer class but not the nested class.

I suspect the problem is that TUnit cannot parse the test or class name when it has a + in it.

TUnit Version

1.6.5

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

Visual Studio

Error Output / Stack Trace

error output is under the "Actual results" section.

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE
  • I've confirmed it works when I use xunit in the same IDE.

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