Skip to content

SetArgDisplayNames for TestCaseData and TestFixtureData #2536

Description

@jnm2
Edit: TestFixtureData.SetName is being made public again after we pulled it from 3.9 now that the behavior is consistent with TestCaseData

TestCaseData.SetName leaves you in an impossible situation explored by #1943 if you are forced to customize parameterized test names and the parameter names contain curlies. To summarize:

The thing that makes me uncomfortable here is that NUnit forces us to use SetName because otherwise the autogenerated test names collide, which in turn forces us to replace curlies with some other character. Feature holes are fine unless the feature is forced on you.

/cc @stewart-r as promised, who said:

Maybe I am guilty of seeing the world through the prism of my own recent experience but I have to say am really surprised that it doesn't seem to affect more people. People test edge cases, any strings with curly braces are edge cases for string manipulation code.... where is the tsunami!?? :-p

Also to say nothing of the escaping problems we ran into with curlies, SetName is just plain verbose. The style just about everyone wants to use, and I agree with them, is "{m}(" + string.Join(", ", customParameterNames) + ")".

We explored different alternatives and this is the only one that addresses all my concerns, @stewart-r's concerns, and @oznetmaster's concerns with the SetName being added to TestFixtureSource (#2529):

namespace NUnit.Framework
{
    public class TestCaseData
    {
+       public TestCaseData SetArgDisplay(params string[] names);
    }
    public class TestFixtureData
    {
+       public TestFixtureData SetName(string name);
+       public TestFixtureData SetName(params string[] names);
    }
}

Usage example for TestFixtureData: .SetArgDisplay("Issue-2464")

NUnit.Framework.Internal.Execution.ParallelExecutionTests(Issue-2464).AllTestsPassed

TestCaseData usage example:

// x = new Person { Name = "Stewart {C} Robertson" }, y = 42
new TestCaseData(x, y, z).SetArgDisplay(x.Name, y)

Resulting test name:

Namespace.FixtureName.MethodName(Stewart {C} Robertson, 42)

SetArgDisplay fills a need that no other solution fills. It's urgent for my real world use cases. If I implement it in time for 3.9, it also allows us to remove TestFixtureData.SetName until we have a proper discussion about expansions and escaping (and whether we'd even want it). Thus I'm marking this design discussion pri:high.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions