Skip to content

Conversation

amishra-u
Copy link
Contributor

JUnitParams generates report names based on parameter values rather than parameter types, which can result in duplicate test names in the XML output. This situation arises when two test methods have identical names but differ in parameter types; however, their string representations may be the same (e.g., Integer 1 and Long 1).

Added logic to ignore tests with duplicate names in test report names.

@amishra-u
Copy link
Contributor Author

@illicitonion can you please review?

@shs96c
Copy link
Collaborator

shs96c commented Jul 25, 2025

#351 recently landed. I'm pretty sure that we still need this PR, but could you please confirm? If we do, I'll be happy to merge this.

Please also accept my apologies for the very slow review.

@amishra-u
Copy link
Contributor Author

#351 recently landed. I'm pretty sure that we still need this PR, but could you please confirm? If we do, I'll be happy to merge this.

Please also accept my apologies for the very slow review.

Yes, we still need this.

@christianladam
Copy link
Contributor

christianladam commented Jul 26, 2025

Can you try adding the following to your .bazelrc to test:

test --jvmopt="-Djunit.jupiter.params.displayname.default=\"[{index}] {displayName}=({arguments})\""

Which would make the output go from:
[1] goGreek=alpha
to:
[1] bootstrap(String)=(alpha)

For https://github.com/bazel-contrib/rules_jvm/blob/main/comparative-tests/src/test/java/com/github/bazel_contrib/contrib_rules_jvm/comparative/ParameterisedTest.java. If you don't want to get the values of each parameter you can just remove the =({arguments}) part.

This change in the default naming for ParameterizedTests would apply after various annotation name settings (see https://docs.junit.org/current/user-guide/#writing-tests-display-names for more details).

@amishra-u
Copy link
Contributor Author

@christianladam this is talking about junitparmsrunner. This flag works for Junit5 Parameterized test.
https://github.com/Pragmatists/JUnitParams/blob/master/src/main/java/junitparams/JUnitParamsRunner.java

@christianladam
Copy link
Contributor

christianladam commented Jul 28, 2025

Do you want it to ignore duplicates? How would one know which result its actually showing? It feels like it'd be better to change the format of the JUnitParams stuff to handle it better. Since JUnitParamsRunner is junit4, do you know what the behavior is when using the standard junit4 test runner provided by bazel? Ideally we'd be handling things the same in both cases. If it's having this issue in both cases, then ideally there'd be a solution that works for both where potentially the JUnitParams formatting via https://github.com/Pragmatists/JUnitParams/blob/master/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java could be overridden or configured. I'm guessing the junit4 code might work fine but the junit5 doesn't because rules_jvm tries to match the behavior of gradle/maven when it comes to the dynamic naming cases.

@amishra-u
Copy link
Contributor Author

@shs96c can you please take a look.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants