-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Labels
Milestone
Description
Background
While working on #4698, I created tests using blank strings like the following.
@Retention(RetentionPolicy.RUNTIME)
@ParameterizedTest
@NullSource
@ValueSource(strings = { "", " ", " ", "\t", "\r", "\r\n", "\n" })
@interface EmptyReasonsTest {
}
That produces display names similar to the following, which are not very useful since the last 7 are identical.

If I wrap the values in single quotes as follows...
@ParameterizedTest(name = "[{index}] reason=''{0}''")
... the results are better.

Proposal
But... I think we can do even better.
Namely if we replace non-printable characters, then configuration like this...
@ParameterizedTest(name = "[{index}] reason=''{0}''")
@NullSource
@ValueSource(strings = { "", " ", " ", "\t", "\r", "\r\n", "\n", "\u200B" })
... could have display names like this:

Proof of Concept
Invoking the following from ParameterizedInvocationNameFormatter.MessageFormatPartialFormatter
's makeReadable()
method resulted in the last screenshot in the Proposal section.
private String replaceNonPrintableCharacters(String string) {
return string
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
.replaceAll("[\\p{Cc}\\p{Cf}\\p{Co}\\p{Cn}]", "?");
}
Related Issues
- Sanitize display names before they are output via the
ConsoleLauncher
#1713 - Quote text-based arguments in display names for parameterized tests #4716
- CSV header names do not work with
{argumentsWithNames}
display name pattern #4783 - Consistently use
name = value
formatting for arguments with names in parameterized tests #4786
sormuras, marcphilipp, jbduncan and Pankraz76