testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Separate `GetDisplayName` out of `ITestDataSource`

Open Youssef1313 opened this issue 9 months ago • 4 comments

I think ITestDataSources shouldn't be concerned with how they are displayed.

I think it may be better to either remove GetDisplayName completely, or introduce it as a separate interface

To be investigated: what is the current behavior if an implementation of GetDisplayName returned null. Are we going to fallback to a "nice" display name that correctly takes into account the parameters of the test?

Youssef1313 avatar Mar 24 '25 10:03 Youssef1313

In the split interface for display name it would be nice to have some helpers that I can use to implement it. Right now you can only implement it from scratch, and have to get all the details of parameter serialization right etc. Or you can prepend some data, but you cannot easily replace the name, but keep the parameter part.

https://github.com/microsoft/testfx/issues/1180#issuecomment-1277155353

nohwnd avatar Mar 25 '25 08:03 nohwnd

We need to discuss more if we need to take this break for v4 or postpone to v5 if it's going to be too hard for users.

Alternative ideas:

  • Treat null value returned from GetDisplayName as "use the default implementation"
  • Expose the internal helper that's used for getting display name.

Youssef1313 avatar Jun 12 '25 18:06 Youssef1313

I would be for the helper approach, because we don't have to limit ourselves to just one helper, and it is easier to give the different parts to the user to use them.

But this solution to this seems tangential to removing the method from ITestDataSource, and can be implemented without breaking change as a new feature in the current version as well.

nohwnd avatar Jun 13 '25 07:06 nohwnd

IIRC, the helper takes TestIdGenerationStrategy or something like that which exists today for backcompat reasons which we may want to break in v4. So might be better to expose the helper in v4 rather than introducing in 3.x and changing signature in v4.

Youssef1313 avatar Jun 13 '25 07:06 Youssef1313

Not going to do this breaking change, at least in v4. Instead, we will automatically use the default display name when GetDisplayName returns null.

Youssef1313 avatar Jun 24 '25 13:06 Youssef1313