TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

`TestMethodIdentifierProperty.TypeName` isn't intended to contain parentheses

Open Youssef1313 opened this issue 9 months ago • 11 comments

https://github.com/thomhurst/TUnit/blob/57effa34626f1b58c37a10aa24d6d68c8ab00d62/TUnit.Engine/Extensions/TestExtensions.cs#L25-L32

https://github.com/thomhurst/TUnit/blob/57effa34626f1b58c37a10aa24d6d68c8ab00d62/TUnit.Core/Extensions/TestContextExtensions.cs#L54-L70

It looks like for the case of a test class with primary constructor and [Arguments] attribute, the arguments are added between parentheses after the type name.

This is not the intended usage of the API. I can see it was done this way to adjust how the hierarchy is displayed on Test Explorer, but the implementation violates the API contract and might break in future, and will likely break any custom extension that tries to read TestMethodIdentifierProperty and interprets it per the API contract.

Unfortunately, fixing this means that the display won't look the way you want it to be. I think the right approach there would be using the ParentTestNodeUid of TestNodeUpdateMessage but it's unfortunately not yet supported in (at least) VS Test Explorer (I don't know about Rider - if it doesn't work there, you can open a report to them). But still it won't work in VS. This is related to https://github.com/microsoft/testfx/issues/3371

Youssef1313 avatar Apr 12 '25 06:04 Youssef1313

Is there any update on custom control of the TE layout? I don't really want to fix this until something like that is ready. As mentioned in my comments on that issue, if I'm injecting different data at the class level, the TE will not show which is which. And that is going to be a bad experience for users.

thomhurst avatar Apr 12 '25 07:04 thomhurst

Is there any update on custom control of the TE layout?

I'd really love to have that done, but so far there are no updates there, unfortunately.

Youssef1313 avatar Apr 12 '25 07:04 Youssef1313

Is there any update on custom control of the TE layout?

I'd really love to have that done, but so far there are no updates there, unfortunately.

:(

Is there any way I, or other users, could raise or put our support behind an issue to the VS team to implement this? I may be naive but it doesn't look like a difficult task to me. The UI is already built to handle item > expand list > item > expand list etc.

All they'd need to do (unless I'm missing context) is map a new custom test node property containing the new path into that.

thomhurst avatar Apr 12 '25 18:04 thomhurst

I think best you can do is to open a request on https://developercommunity.visualstudio.com/, affected users can upvote it.

Youssef1313 avatar Apr 13 '25 08:04 Youssef1313

Thanks @Youssef1313 - I've raised this: https://developercommunity.visualstudio.com/t/Allow-test-frameworks-to-control-the-tes/10889052

thomhurst avatar Apr 13 '25 11:04 thomhurst

@thomhurst Note that there is a niche case where TUnit is already broken in TE today due to the expectations of how this property is expected to be used.

e.g (note the test class is in global namespace):

[Arguments("Hello.1")]
[Arguments("World.2")]
public class MoreTests(string title)
{
    [Test]
    public void ClassLevelDataRow()
    {
    }
}

Image

Youssef1313 avatar Apr 14 '25 08:04 Youssef1313

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 15 '25 00:05 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 15 '25 00:06 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jun 21 '25 00:06 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 29 '25 00:10 github-actions[bot]