Skip to content

Include parameter names in default name of @ParameterizedTest #2040

Closed
@vlsi

Description

@vlsi

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

changed the title [-]Print parameter names in default name of @ParameterizedTest[/-] [+]Include parameter names in default name of @ParameterizedTest[/+] on Oct 4, 2019
added this to the 5.6 M1 milestone on Oct 4, 2019
sbrannen

sbrannen commented on Oct 4, 2019

@sbrannen
Member

Tentatively slated for 5.6 M1 solely for the purpose of team discussion and triaging.

sbrannen

sbrannen commented on Oct 4, 2019

@sbrannen
Member

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

vlsi commented on Oct 4, 2019

@vlsi
ContributorAuthor

You assume I use Java, however, Kotlin does retain parameter names always 😉

marcphilipp

marcphilipp commented on Oct 5, 2019

@marcphilipp
Member

@sbrannen Could we check whether parameter names are present and include them only if so?

sbrannen

sbrannen commented on Oct 5, 2019

@sbrannen
Member

@sbrannen Could we check whether parameter names are present and include them only if so?

Yes. See java.lang.reflect.Parameter.isNamePresent().

modified the milestones: 5.6 M1, 5.6 M2 on Oct 10, 2019
marcphilipp

marcphilipp commented on Oct 24, 2019

@marcphilipp
Member

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 for ArgumentsAccessor and ArgumentsAggregator).

15 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @sbrannen@vlsi@marcphilipp@juliette-derancourt

    Issue actions

      Include parameter names in default name of @ParameterizedTest · Issue #2040 · junit-team/junit5