-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Overview
While working on #4716, by merely inspecting the code I theorized that there must be something wrong with how useHeadersInDisplayName
works. So, I wrote an example and confirmed it.
Specifically, when I introduced the useHeadersInDisplayName
support for @CsvSource
and @CsvFileSource
in JUnit Jupiter 5.8.2, I used a hack to create the "header name = argument value" entries in the display names using Named
.
Unfortunately, that hack only works with the {arguments}
display name pattern.
Thus, the examples in the User Guide explicitly declare that as follows.
@ParameterizedTest(name = "[{index}] {arguments}")
@CsvSource(useHeadersInDisplayName = true, textBlock = """
FRUIT, RANK
apple, 1
banana, 2
'lemon, lime', 0xF1
strawberry, 700_000
""")
void testWithCsvSource(String fruit, int rank) {
// ...
}
That results in display names like [1] FRUIT = apple, RANK = 1
, which is the desired result.
However, if you simply declare @ParameterizedTest
, without specifying an alternative name
pattern, that results in display names like [1] fruit=FRUIT = apple, rank=RANK = 1
, which is obviously not the desired result. This is due to the fact that <parameter name>=
is prepended to the argument value (or name-value pair as is the case for useHeadersInDisplayName
).
Aside from the fact that we obviously have different formatting for the two features (x=y
vs. x = y
), we should ensure that the useHeadersInDisplayName
feature works properly when using the default display name pattern (or one equivalent to {argumentsWithNames}
.