Closed
Description
Suppose I have a test:
@ParameterizedTest
@MethodSource("implementationsAndIps")
public void test(String httpImplementation, String targetHost, InetAddress sourceIp,
WireMockServer server, JMeterVariables vars) throws SocketException {
The result looks unreadable:
[3] HttpClient4, 127.0.0.1, /127.0.0.1
[1] HttpClient4, 127.0.0.1, /fe80:0:0:0:0:0:0:1%lo0
[7] Java, 127.0.0.1, /fe80:0:0:0:0:0:0:1%lo0
[4] HttpClient4, [::1], /fe80:0:0:0:0:0:0:1%lo0
[5] HttpClient4, [::1], /0:0:0:0:0:0:0:1%lo0
[8] Java, 127.0.0.1, /0:0:0:0:0:0:0:1%lo0
[10] Java, [::1], /fe80:0:0:0:0:0:0:1%lo0
It does not really help if the test fails.
That means every time I use @ParameterizedTest
I have to declare test name explicitly.
That is sad.
What if JUnit generated something like
[3] httpImplementation=HttpClient4, targetHost=127.0.0.1, sourceIp=/127.0.0.1
[1] httpImplementation=HttpClient4, targetHost=127.0.0.1, sourceIp=/fe80:0:0:0:0:0:0:1%lo0
...
?
It would make lots of tests and test failures easier to understand.
I'm OK if it is {arguments_with_names}
. Then I could create @ParameterizedTestWithArgNames
annotation that uses detailed name.
PS. I've seen #1154, however, I don't really want to deal and/or declare resolvers.
Activity
[-]Print parameter names in default name of @ParameterizedTest[/-][+]Include parameter names in default name of @ParameterizedTest[/+]sbrannen commentedon Oct 4, 2019
Tentatively slated for 5.6 M1 solely for the purpose of team discussion and triaging.
sbrannen commentedon Oct 4, 2019
FYI: this would need to be an opt-in feature. In addition, parameter names are not always present in the compiled byte code. To include them in the byte code, the test code must be compiled with the
-parameters
compiler flag.vlsi commentedon Oct 4, 2019
You assume I use Java, however, Kotlin does retain parameter names always 😉
marcphilipp commentedon Oct 5, 2019
@sbrannen Could we check whether parameter names are present and include them only if so?
sbrannen commentedon Oct 5, 2019
Yes. See
java.lang.reflect.Parameter.isNamePresent()
.marcphilipp commentedon Oct 24, 2019
Team Decision: Introduce new
{arguments_with_names}
pattern and make it the default. Only include parameter names if present in bytecode and parameter types are known (e.g. not forArgumentsAccessor
andArgumentsAggregator
).15 remaining items