You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apostrophe in display name breaks name generation for @ParameterizedTestΒ #3235
Review report at build/reports/tests/test/index.html
Note: the repro project is a bit more complex than the above:
TestK is a pure Kotlin version
TestJ is a pure Java version
Test is the problematic version with Kotlin apostrophes.
I made them really similar so it's easy to compare their outputs.
Expected
No {0} anywhere.
It works correctly without apostrophes: build/reports/tests/test/classes/com.example.MyTestK.html
Actual
When the method name contains ', the {0} is not substituted.
It fails formatting the name when apostrophes are added: build/reports/tests/test/classes/com.example.MyTest.html
Context
Used versions (Jupiter/Vintage/Platform): 5.9.2
Build Tool/IDE: Gradle / IDEA, but likely irrelevant.
Deliverables
I think the problem might be around ParameterizedTestNameFormatter, but didn't debug it.
JUnit uses java.text.MessageFormat to process display names for parameterized tests.
Here's an excerpt from the User Guide:
Please note that name is a MessageFormat pattern. Thus, a single quote (') needs to be represented as a doubled single quote ('') in order to be displayed.
That means if you renamed your test method to displayName''Zero, it should work.
I say "should", because I have not tested it myself (since I don't use Kotlin).
Yep that works as expected, but imagine test names like fun `foo shouldn''t bar`(baz: Qux) π€’. Of course in case of contractions it's easy to expand to "should not", but there are cases when you don't have an option, like foo 'bar' baz, although that might "just work" because the quotation is closed.
Could the name be pre-escaped somehow for MessageFormat, since using that replacement tool is just an implementation detail?
in order to be displayed.
I think that part of the user guide should be more explicit that if you have a ' in display name, things will break other than "not showing".
I assumed that {displayName} would temporarily have to be replaced with something that doesn't contain curly brackets. So, yes, that appears to be the correct approach.
Feel free to submit a PR.
If you would like to get it included in JUnit 5.10, please do so in the coming days or week since we are now finalizing the feature set for 5.10.
In your PR, please include Java-based tests in addition to Kotlin-based tests.
changed the title [-]Apostrophe in Kotlin function name breaks ParameterizedTest(name)[/-][+]Apostrophe in display name breaks name generation for `@ParameterizedTest`[/+]on Apr 21, 2023
Activity
Repro for junit-team/junit-framework#3235
sbrannen commentedon Apr 7, 2023
JUnit uses
java.text.MessageFormatto process display names for parameterized tests.Here's an excerpt from the User Guide:
That means if you renamed your test method to
displayName''Zero, it should work.I say "should", because I have not tested it myself (since I don't use Kotlin).
Please let us know if that works for you.
TWiStErRob commentedon Apr 7, 2023
Yep that works as expected, but imagine test names like
fun `foo shouldn''t bar`(baz: Qux)π€’. Of course in case of contractions it's easy to expand to "should not", but there are cases when you don't have an option, likefoo 'bar' baz, although that might "just work" because the quotation is closed.Could the name be pre-escaped somehow for
MessageFormat, since using that replacement tool is just an implementation detail?I think that part of the user guide should be more explicit that if you have a
'in display name, things will break other than "not showing".25 remaining items
alemendoza-v commentedon Apr 20, 2023
Should I crΓ©ate a PR for it?
sbrannen commentedon Apr 21, 2023
@alemendoza-v,
I assumed that
{displayName}would temporarily have to be replaced with something that doesn't contain curly brackets. So, yes, that appears to be the correct approach.Feel free to submit a PR.
If you would like to get it included in JUnit 5.10, please do so in the coming days or week since we are now finalizing the feature set for 5.10.
In your PR, please include Java-based tests in addition to Kotlin-based tests.
[-]Apostrophe in Kotlin function name breaks ParameterizedTest(name)[/-][+]Apostrophe in display name breaks name generation for `@ParameterizedTest`[/+]Add release note entry for issue junit-team#3235
Move release note for #3235/#3264 to 5.9.3
Do not parse {displayName} for @ParameterizedTest using MessageFormat
Move release note for #3235/#3264 to 5.9.3
Do not parse {displayName} for @ParameterizedTest using MessageFormat