Skip to content

Allow DataRow to customize only the arguments part of the display name #11770

Description

Summary

Setting DisplayName on [DataRow] replaces the entire test name, including the test method name. This proposal is about a way to name just the data row while keeping the method name: Parse_ReturnsNull (empty input) instead of empty input.

Background and Motivation

Without DisplayName, a data row is named <method display name> (<arguments>). With it, the value is used as-is and the method name is dropped. For example, on MSTest 4.4.1 / MTP 2.4.1:

[TestClass]
public class ParserTests
{
    [TestMethod]
    [DataRow("", DisplayName = "empty input")]
    public void Parse_ReturnsNull(string input) { }

    [TestMethod]
    [DataRow("", DisplayName = "empty input")]
    public void Validate_ReturnsFalse(string input) { }
}
passed empty input (0ms)
passed empty input (0ms)

Two different tests end up with the same name, and the name alone no longer says which method a row belongs to. TestDataRow<T>.DisplayName behaves the same way.

Arguments are often not meaningful on their own (empty strings, magic numbers, long values), so a short description of the row is what makes the name readable. Today, choosing one means losing the method name. The only built-in way to keep both is to repeat the method name on every row, e.g. DisplayName = nameof(Parse_ReturnsNull) + " (empty input)". A similar case came up in the discussion on #1635.

Proposed Feature

A way to customize only the row-specific part of the name, so that:

  • A row on Parse_ReturnsNull described as "empty input" is shown as Parse_ReturnsNull (empty input).
  • [TestMethod(DisplayName = "...")] is still honored, as it already is for the default name.
  • Ideally, the same applies to TestDataRow<T>.

Existing DisplayName values should keep working as they do today, since many projects use them as full test names (like the docs example DisplayName = "Functional Case FC100.1").

Several designs could achieve this, each with different trade-offs:

  1. A new opt-in property on DataRowAttribute / TestDataRow<T> that replaces only the arguments part, e.g. [DataRow("", ArgumentsDisplayName = "empty input")] (name just illustrative). Explicit and non-breaking, at the cost of one more property next to DisplayName.
  2. Placeholders in DisplayName, similar to NUnit's TestName templates ({m} for the method name, {a} for the arguments), e.g. DisplayName = "{m} (empty input)". Flexible, but it gives braces in existing names a new meaning unless it's opt-in.
  3. A setting (e.g. in testconfig.json / .runsettings) that makes DisplayName replace only the arguments part. A single switch, but the same attribute would render differently depending on project configuration.

Alternative Designs

Subclassing DataRowAttribute. GetDisplayName is virtual, so this works today:

public sealed class LabeledDataRowAttribute(params object?[]? data) : DataRowAttribute(data)
{
    public override string? GetDisplayName(MethodInfo methodInfo, object?[]? data)
        => string.IsNullOrWhiteSpace(DisplayName)
            ? base.GetDisplayName(methodInfo, data)
            : $"{methodInfo.Name} ({DisplayName})";
}

However, every project has to carry its own copy, it doesn't cover TestDataRow<T>, and this straightforward version ignores [TestMethod(DisplayName = "...")], since it only sees the method's name. Matching the built-in behavior means re-implementing the framework's naming logic.

Repeating the method name in DisplayName. Works without custom code, but it's verbose and has to be done on every row.

Activity

  1. Evangelink commented on Oct 7, 2026

    @Evangelink
    Member

    Daniel Gil (@DanielGilOrtiz) you got lucky! I was able to squeeze the feature in the release of MSTest 4.5, please let us know if you have any problem or feedback

  2. DanielGilOrtiz commented on Oct 8, 2026

    @DanielGilOrtiz
    Author

    Amaury Levé (@Evangelink) Thanks again for getting this into the release!

    I’ll be away for the next two weeks, so I probably won’t be able to test it properly until I’m back. From what I’ve seen so far, though, it seems to be working properly in the Test Explorer from both VS Code and Visual Studio 2026. I’ll also check how it behaves in ADO when I’m back.

    I also really appreciate how responsive you’ve been and how much you take all this feedback into account. It’s been great seeing how quickly things move as a result.

    And thanks as well for looking into testconfig.json support for Playwright. I think that’s a really nice step towards bringing that part of the .NET experience a bit more up to date.

    Thanks again, and I’ll report back once I’m back!

  3. Evangelink commented on Oct 9, 2026

    @Evangelink
    Member

    Thank you so much for the warm feedback, I am super happy to read it! Always feel free to post any question, issue or suggestion :)

  4. DanielGilOrtiz commented on Oct 30, 2026

    @DanielGilOrtiz
    Author

    Amaury Levé (@Evangelink) Sorry for the delayed response. I'm back now, and the feature is fully tested. It works perfectly in Test Explorer (VS Code, Visual Studio, and even in the HTML report). However, we've found a bug that makes the test argument repeated across all iterations of a DataRow test in ADO. This happens regardless of whether you use ArgumentsDisplayName, DisplayName, or neither of them. Thanks!

  5. Evangelink commented on Oct 30, 2026

    @Evangelink
    Member

    Thanks for the confirmation! We will include the fix for the other bug in 4.5.3, feel free to test it when you can.

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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions