@@ -1242,26 +1242,26 @@ Executing the above test class yields the following output:
1242
1242
1243
1243
....
1244
1244
FruitTests ✔
1245
- ├─ [1] fruit = apple ✔
1245
+ ├─ [1] fruit = " apple" ✔
1246
1246
│ └─ QuantityTests ✔
1247
1247
│ ├─ [1] quantity = 23 ✔
1248
1248
│ │ └─ test(Duration) ✔
1249
- │ │ ├─ [1] duration = PT1H ✔
1250
- │ │ └─ [2] duration = PT2H ✔
1249
+ │ │ ├─ [1] duration = " PT1H" ✔
1250
+ │ │ └─ [2] duration = " PT2H" ✔
1251
1251
│ └─ [2] quantity = 42 ✔
1252
1252
│ └─ test(Duration) ✔
1253
- │ ├─ [1] duration = PT1H ✔
1254
- │ └─ [2] duration = PT2H ✔
1255
- └─ [2] fruit = banana ✔
1253
+ │ ├─ [1] duration = " PT1H" ✔
1254
+ │ └─ [2] duration = " PT2H" ✔
1255
+ └─ [2] fruit = " banana" ✔
1256
1256
└─ QuantityTests ✔
1257
1257
├─ [1] quantity = 23 ✔
1258
1258
│ └─ test(Duration) ✔
1259
- │ ├─ [1] duration = PT1H ✔
1260
- │ └─ [2] duration = PT2H ✔
1259
+ │ ├─ [1] duration = " PT1H" ✔
1260
+ │ └─ [2] duration = " PT2H" ✔
1261
1261
└─ [2] quantity = 42 ✔
1262
1262
└─ test(Duration) ✔
1263
- ├─ [1] duration = PT1H ✔
1264
- └─ [2] duration = PT2H ✔
1263
+ ├─ [1] duration = " PT1H" ✔
1264
+ └─ [2] duration = " PT2H" ✔
1265
1265
....
1266
1266
1267
1267
[[writing-tests-dependency-injection]]
@@ -1649,9 +1649,9 @@ following.
1649
1649
1650
1650
....
1651
1651
palindromes(String) ✔
1652
- ├─ [1] candidate = racecar ✔
1653
- ├─ [2] candidate = radar ✔
1654
- └─ [3] candidate = able was I ere I saw elba ✔
1652
+ ├─ [1] candidate = " racecar" ✔
1653
+ ├─ [2] candidate = " radar" ✔
1654
+ └─ [3] candidate = " able was I ere I saw elba" ✔
1655
1655
....
1656
1656
1657
1657
The same `@ValueSource` annotation can be used to specify the source of arguments for a
@@ -1668,13 +1668,13 @@ following.
1668
1668
1669
1669
....
1670
1670
PalindromeTests ✔
1671
- ├─ [1] candidate = racecar ✔
1671
+ ├─ [1] candidate = " racecar" ✔
1672
1672
│ ├─ palindrome() ✔
1673
1673
│ └─ reversePalindrome() ✔
1674
- ├─ [2] candidate = radar ✔
1674
+ ├─ [2] candidate = " radar" ✔
1675
1675
│ ├─ palindrome() ✔
1676
1676
│ └─ reversePalindrome() ✔
1677
- └─ [3] candidate = able was I ere I saw elba ✔
1677
+ └─ [3] candidate = " able was I ere I saw elba" ✔
1678
1678
├─ palindrome() ✔
1679
1679
└─ reversePalindrome() ✔
1680
1680
....
@@ -2139,7 +2139,7 @@ It is also possible to provide a `Stream`, `DoubleStream`, `IntStream`, `LongStr
2139
2139
iterator is wrapped in a `java.util.function.Supplier`. The following example demonstrates
2140
2140
how to provide a `Supplier` of a `Stream` of named arguments. This parameterized test
2141
2141
method will be invoked twice: with the values `"apple"` and `"banana"` and with display
2142
- names `Apple` and `Banana`, respectively.
2142
+ names `" Apple" ` and `" Banana" `, respectively.
2143
2143
2144
2144
[source,java,indent=0]
2145
2145
----
@@ -2252,10 +2252,10 @@ void testWithCsvSource(String fruit, int rank) {
2252
2252
The generated display names for the previous example include the CSV header names.
2253
2253
2254
2254
----
2255
- [1] FRUIT = apple, RANK = 1
2256
- [2] FRUIT = banana, RANK = 2
2257
- [3] FRUIT = lemon, lime, RANK = 0xF1
2258
- [4] FRUIT = strawberry, RANK = 700_000
2255
+ [1] FRUIT = " apple" , RANK = "1"
2256
+ [2] FRUIT = " banana" , RANK = "2"
2257
+ [3] FRUIT = " lemon, lime" , RANK = " 0xF1"
2258
+ [4] FRUIT = " strawberry" , RANK = " 700_000"
2259
2259
----
2260
2260
2261
2261
In contrast to CSV records supplied via the `value` attribute, a text block can contain
@@ -2332,20 +2332,20 @@ The following listing shows the generated display names for the first two parame
2332
2332
test methods above.
2333
2333
2334
2334
----
2335
- [1] country = Sweden, reference = 1
2336
- [2] country = Poland, reference = 2
2337
- [3] country = United States of America, reference = 3
2338
- [4] country = France, reference = 700_000
2335
+ [1] country = " Sweden" , reference = "1"
2336
+ [2] country = " Poland" , reference = "2"
2337
+ [3] country = " United States of America" , reference = "3"
2338
+ [4] country = " France" , reference = " 700_000"
2339
2339
----
2340
2340
2341
2341
The following listing shows the generated display names for the last parameterized test
2342
2342
method above that uses CSV header names.
2343
2343
2344
2344
----
2345
- [1] COUNTRY = Sweden, REFERENCE = 1
2346
- [2] COUNTRY = Poland, REFERENCE = 2
2347
- [3] COUNTRY = United States of America, REFERENCE = 3
2348
- [4] COUNTRY = France, REFERENCE = 700_000
2345
+ [1] COUNTRY = " Sweden" , REFERENCE = "1"
2346
+ [2] COUNTRY = " Poland" , REFERENCE = "2"
2347
+ [3] COUNTRY = " United States of America" , REFERENCE = "3"
2348
+ [4] COUNTRY = " France" , REFERENCE = " 700_000"
2349
2349
----
2350
2350
2351
2351
In contrast to the default syntax used in `@CsvSource`, `@CsvFileSource` uses a double
@@ -2668,11 +2668,18 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsAggregator_w
2668
2668
==== Customizing Display Names
2669
2669
2670
2670
By default, the display name of a parameterized class or test invocation contains the
2671
- invocation index and the `String` representation of all arguments for that specific
2672
- invocation. Each argument is preceded by its parameter name (unless the argument is only
2673
- available via an `ArgumentsAccessor` or `ArgumentAggregator`), if the parameter name is
2674
- present in the bytecode (for Java, test code must be compiled with the `-parameters`
2675
- compiler flag; for Kotlin, with `-java-parameters`).
2671
+ invocation index and a comma-separated list of the `String` representations of all
2672
+ arguments for that specific invocation. If parameter names are present in the bytecode,
2673
+ each argument will be preceded by its parameter name and an equals sign (unless the
2674
+ argument is only available via an `ArgumentsAccessor` or `ArgumentAggregator`) – for
2675
+ example, `firstName = "Jane"`.
2676
+
2677
+ [TIP]
2678
+ ====
2679
+ To ensure that parameter names are present in the bytecode, test code must be compiled
2680
+ with the `-parameters` compiler flag for Java or with the `-java-parameters` compiler flag
2681
+ for Kotlin.
2682
+ ====
2676
2683
2677
2684
However, you can customize invocation display names via the `name` attribute of the
2678
2685
`@ParameterizedClass` or `@ParameterizedTest` annotation as in the following example.
@@ -2688,9 +2695,9 @@ the following.
2688
2695
2689
2696
....
2690
2697
Display name of container ✔
2691
- ├─ 1 ==> the rank of ' apple' is 1 ✔
2692
- ├─ 2 ==> the rank of ' banana' is 2 ✔
2693
- └─ 3 ==> the rank of ' lemon, lime' is 3 ✔
2698
+ ├─ 1 ==> the rank of " apple" is "1" ✔
2699
+ ├─ 2 ==> the rank of " banana" is "2" ✔
2700
+ └─ 3 ==> the rank of " lemon, lime" is "3" ✔
2694
2701
....
2695
2702
======
2696
2703
@@ -2777,6 +2784,70 @@ Note that `argumentSet(String, Object...)` is a static factory method defined in
2777
2784
`org.junit.jupiter.params.provider.Arguments` interface.
2778
2785
====
2779
2786
2787
+ [[writing-tests-parameterized-tests-display-names-quoted-text]]
2788
+ ===== Quoted Text-based Arguments
2789
+
2790
+ As of JUnit Jupiter 6.0, text-based arguments in display names for parameterized tests are
2791
+ quoted by default. In this context, any `CharSequence` (such as a `String`) or `Character`
2792
+ is considered text. A `CharSequence` is wrapped in double quotes (`"`), and a `Character`
2793
+ is wrapped in single quotes (`'`).
2794
+
2795
+ Special characters will be escaped in the quoted text. For example, carriage returns and
2796
+ line feeds will be escaped as `\\r` and `\\n`, respectively. In addition, any ISO control
2797
+ character will be represented as a question mark (`?`) in the quoted text.
2798
+
2799
+ [TIP]
2800
+ ====
2801
+ This feature can be disabled by setting the `quoteTextArguments` attributes in
2802
+ `@ParameterizedClass` and `@ParameterizedTest` to `false`.
2803
+ ====
2804
+
2805
+ For example, given a string argument `"line 1\nline 2"`, the physical representation in
2806
+ the display name will be `"\"line 1\\nline 2\""` which is printed as `"line 1\nline 2"`.
2807
+ Similarly, given a string argument `"\t"`, the physical representation in the display name
2808
+ will be `"\"\\t\""` which is printed as `"\t"` instead of a blank string or invisible tab
2809
+ character. The same applies for a character argument `'\t'`, whose physical representation
2810
+ in the display name would be `"'\\t'"` which is printed as `'\t'`.
2811
+
2812
+ For a concrete example, if you run the first `nullEmptyAndBlankStrings(String text)`
2813
+ parameterized test method from the
2814
+ <<writing-tests-parameterized-tests-sources-null-and-empty>> section above, the following
2815
+ display names are generated.
2816
+
2817
+ ----
2818
+ [1] text = null
2819
+ [2] text = ""
2820
+ [3] text = " "
2821
+ [4] text = " "
2822
+ [5] text = "\t"
2823
+ [6] text = "\n"
2824
+ ----
2825
+
2826
+ If you run the first `testWithCsvSource(String fruit, int rank)` parameterized test method
2827
+ from the <<writing-tests-parameterized-tests-sources-CsvSource>> section above, the
2828
+ following display names are generated.
2829
+
2830
+ ----
2831
+ [1] fruit = "apple", rank = "1"
2832
+ [2] fruit = "banana", rank = "2"
2833
+ [3] fruit = "lemon, lime", rank = "0xF1"
2834
+ [4] fruit = "strawberry", rank = "700_000"
2835
+ ----
2836
+
2837
+ [NOTE]
2838
+ ====
2839
+ The original source arguments are quoted when generating a display name, and this occurs
2840
+ before any implicit or explicit argument conversion is performed.
2841
+
2842
+ For example, if a parameterized test accepts `3.14` as a `float` argument that was
2843
+ converted from `"3.14"` as an input string, `"3.14"` will be present in the display name
2844
+ instead of `3.14`. You can see the effect of this with the `rank` values in the above
2845
+ example.
2846
+ ====
2847
+
2848
+ [[writing-tests-parameterized-tests-display-names-default-pattern]]
2849
+ ===== Default Display Name Pattern
2850
+
2780
2851
If you'd like to set a default name pattern for all parameterized classes and tests in
2781
2852
your project, you can declare the `junit.jupiter.params.displayname.default` configuration
2782
2853
parameter in the `junit-platform.properties` file as demonstrated in the following example (see
@@ -2787,6 +2858,9 @@ parameter in the `junit-platform.properties` file as demonstrated in the followi
2787
2858
junit.jupiter.params.displayname.default = {index}
2788
2859
----
2789
2860
2861
+ [[writing-tests-parameterized-tests-display-names-precedence-rules]]
2862
+ ===== Precedence Rules
2863
+
2790
2864
The display name for a parameterized class or test is determined according to the
2791
2865
following precedence rules:
2792
2866
0 commit comments