Skip to content

Commit a092cc8

Browse files
committed
Simplify anchors in parameterized-classes-and-tests.adoc
1 parent 575f741 commit a092cc8

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

documentation/modules/ROOT/pages/extensions/parameter-resolution.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ to resolve any conflicts.
101101

102102
Parameterized tests are another potential source of conflict. Ensure that tests annotated
103103
with `@ParameterizedTest` are not also annotated with `@Test` and see
104-
xref:writing-tests/parameterized-classes-and-tests.adoc#tests-consuming-arguments[Consuming Arguments] for more details.
104+
xref:writing-tests/parameterized-classes-and-tests.adoc#consuming-arguments[Consuming Arguments] for more details.

documentation/modules/ROOT/pages/writing-tests/display-names.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include::example$java/example/DisplayNameDemo.java[tags=user_guide]
1212
[NOTE]
1313
====
1414
Control characters in text-based arguments in display names for parameterized tests are
15-
escaped by default. See xref:writing-tests/parameterized-classes-and-tests.adoc#tests-display-names-quoted-text[Quoted Text-based Arguments]
15+
escaped by default. See xref:writing-tests/parameterized-classes-and-tests.adoc#display-names-quoted-text[Quoted Text-based Arguments]
1616
for details.
1717
1818
Any remaining ISO control characters in a display name will be replaced as follows.

documentation/modules/ROOT/pages/writing-tests/parameterized-classes-and-tests.adoc

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ to give it a try and provide feedback to the JUnit team so they can improve and
1414
xref:api-evolution.adoc[promote] this feature.
1515

1616
Regardless of whether you are parameterizing a test method or a test class, you must
17-
declare at least one <<tests-sources, source>> that will
17+
declare at least one <<sources, source>> that will
1818
provide the arguments for each invocation and then
19-
<<tests-consuming-arguments, consume>> the arguments in the
19+
<<consuming-arguments, consume>> the arguments in the
2020
parameterized method or class, respectively.
2121

2222
The following example demonstrates a parameterized test that uses the `@ValueSource`
@@ -63,24 +63,24 @@ PalindromeTests ✔
6363
└─ reversePalindrome() ✔
6464
....
6565

66-
[[tests-setup]]
66+
[[setup]]
6767
== Required Setup
6868

6969
In order to use parameterized classes or tests you need to add a dependency on the
7070
`junit-jupiter-params` artifact. Please refer to xref:appendix.adoc#dependency-metadata[Dependency Metadata] for details.
7171

72-
[[tests-consuming-arguments]]
72+
[[consuming-arguments]]
7373
== Consuming Arguments
7474

75-
[[tests-consuming-arguments-methods]]
75+
[[consuming-arguments-methods]]
7676
=== Parameterized Tests
7777

7878
Parameterized test methods _consume_ arguments directly from the configured source (see
79-
<<tests-sources>>) following a one-to-one correlation between
79+
<<sources>>) following a one-to-one correlation between
8080
argument source index and method parameter index (see examples in
81-
<<tests-sources-CsvSource>>). However, a parameterized test
81+
<<sources-CsvSource>>). However, a parameterized test
8282
method may also choose to _aggregate_ arguments from the source into a single object
83-
passed to the method (see <<tests-argument-aggregation>>).
83+
passed to the method (see <<argument-aggregation>>).
8484
Additional arguments may also be provided by a `ParameterResolver` (e.g., to obtain an
8585
instance of `TestInfo`, `TestReporter`, etc.). Specifically, a parameterized test method
8686
must declare formal parameters according to the following rules.
@@ -95,25 +95,25 @@ parameterized method at the same index in the method's formal parameter list. An
9595
_aggregator_ is any parameter of type `{ArgumentsAccessor}` or any parameter annotated
9696
with `{AggregateWith}`.
9797

98-
[[tests-consuming-arguments-classes]]
98+
[[consuming-arguments-classes]]
9999
=== Parameterized Classes
100100

101101
Parameterized classes _consume_ arguments directly from the configured source (see
102-
<<tests-sources>>); either via their unique constructor or via
102+
<<sources>>); either via their unique constructor or via
103103
field injection. If a `{Parameter}`-annotated field is declared in the parameterized class
104104
or one of its superclasses, field injection will be used. Otherwise, constructor injection
105105
will be used.
106106

107-
[[tests-consuming-arguments-constructor-injection]]
107+
[[consuming-arguments-constructor-injection]]
108108
==== Constructor Injection
109109

110110
WARNING: Constructor injection can only be used with the (default) `PER_METHOD`
111111
xref:writing-tests/test-instance-lifecycle.adoc[test instance lifecycle] mode. Please use
112-
<<tests-consuming-arguments-field-injection, field injection>>
112+
<<consuming-arguments-field-injection, field injection>>
113113
with the `PER_CLASS` mode instead.
114114

115115
For constructor injection, the same rules apply as defined for
116-
<<tests-consuming-arguments-methods, parameterized tests>>
116+
<<consuming-arguments-methods, parameterized tests>>
117117
above. In the following example, two arguments are injected into the constructor of the
118118
test class.
119119

@@ -130,7 +130,7 @@ of declaring a test class constructor.
130130
include::example$java/example/ParameterizedRecordDemo.java[tags=example]
131131
----
132132

133-
[[tests-consuming-arguments-field-injection]]
133+
[[consuming-arguments-field-injection]]
134134
==== Field Injection
135135

136136
For field injection, the following rules apply for fields annotated with `@Parameter`.
@@ -161,17 +161,17 @@ If field injection is used, no constructor parameters will be resolved with argu
161161
the source. Other xref:writing-tests/dependency-injection-for-constructors-and-methods.adoc[`ParameterResolver` extensions]
162162
may resolve constructor parameters as usual, though.
163163

164-
[[tests-consuming-arguments-lifecycle-method]]
164+
[[consuming-arguments-lifecycle-method]]
165165
==== Lifecycle Methods
166166

167167
`{BeforeParameterizedClassInvocation}` and `{AfterParameterizedClassInvocation}` can also
168168
be used to consume arguments if their `injectArguments` attribute is set to `true` (the
169169
default). If so, their method signatures must follow the same rules apply as defined for
170-
<<tests-consuming-arguments-methods, parameterized tests>> and
170+
<<consuming-arguments-methods, parameterized tests>> and
171171
additionally use the same parameter types as the _indexed parameters_ of the parameterized
172172
test class. Please refer to the Javadoc of `{BeforeParameterizedClassInvocation}` and
173173
`{AfterParameterizedClassInvocation}` for details and to the
174-
<<tests-lifecycle-interop-classes, Lifecycle>> section for an
174+
<<lifecycle-interop-classes, Lifecycle>> section for an
175175
example.
176176

177177
[NOTE]
@@ -189,14 +189,14 @@ method, you must specify the `autoCloseArguments = false` on the `{Parameterized
189189
invocations.
190190
====
191191

192-
[[tests-consuming-arguments-other-extensions]]
192+
[[consuming-arguments-other-extensions]]
193193
=== Other Extensions
194194

195195
Other extensions can access the parameters and resolved arguments of a parameterized test
196196
or class by retrieving a `{ParameterInfo}` object from the `{ExtensionContext_Store}`.
197197
Please refer to the Javadoc of `{ParameterInfo}` for details.
198198

199-
[[tests-sources]]
199+
[[sources]]
200200
== Sources of Arguments
201201

202202
Out of the box, JUnit Jupiter provides quite a few _source_ annotations. Each of the
@@ -208,7 +208,7 @@ TIP: All source annotations in this section are applicable to both `{Parameteriz
208208
and `{ParameterizedTest}`. For the sake of brevity, the examples in this section will only
209209
show how to use them with `{ParameterizedTest}` methods.
210210

211-
[[tests-sources-ValueSource]]
211+
[[sources-ValueSource]]
212212
=== @ValueSource
213213

214214
`@ValueSource` is one of the simplest possible sources. It lets you specify a single
@@ -236,7 +236,7 @@ the values `1`, `2`, and `3` respectively.
236236
include::example$java/example/ParameterizedTestDemo.java[tags=ValueSource_example]
237237
----
238238

239-
[[tests-sources-null-and-empty]]
239+
[[sources-null-and-empty]]
240240
=== Null and Empty Sources
241241

242242
In order to check corner cases and verify proper behavior of our software when it is
@@ -259,7 +259,7 @@ for parameterized tests that accept a single argument.
259259

260260
If you need to supply multiple varying types of _blank_ strings to a parameterized
261261
class or test, you can achieve that using
262-
<<tests-sources-ValueSource>> -- for example,
262+
<<sources-ValueSource>> -- for example,
263263
`@ValueSource(strings = {"{nbsp}", "{nbsp}{nbsp}{nbsp}", "\t", "\n"})`.
264264

265265
You can also combine `@NullSource`, `@EmptySource`, and `@ValueSource` to test a wider
@@ -283,7 +283,7 @@ NOTE: Both variants of the `nullEmptyAndBlankStrings(String)` parameterized test
283283
result in six invocations: 1 for `null`, 1 for the empty string, and 4 for the explicit
284284
blank strings supplied via `@ValueSource`.
285285

286-
[[tests-sources-EnumSource]]
286+
[[sources-EnumSource]]
287287
=== @EnumSource
288288

289289
`@EnumSource` provides a convenient way to use `Enum` constants.
@@ -351,7 +351,7 @@ range of constants while excluding specific values from that range as shown belo
351351
include::example$java/example/ParameterizedTestDemo.java[tags=EnumSource_range_exclude_example]
352352
----
353353

354-
[[tests-sources-MethodSource]]
354+
[[sources-MethodSource]]
355355
=== @MethodSource
356356

357357
`{MethodSource}` allows you to refer to one or more _factory_ methods of the test class
@@ -439,7 +439,7 @@ can be referenced by its fully qualified method name, e.g.
439439
include::example$java/example/MethodSourceParameterResolutionDemo.java[tags=parameter_resolution_MethodSource_example]
440440
----
441441

442-
[[tests-sources-FieldSource]]
442+
[[sources-FieldSource]]
443443
=== @FieldSource
444444

445445
`{FieldSource}` allows you to refer to one or more fields of the test class or external
@@ -466,7 +466,7 @@ a single argument.
466466
[WARNING]
467467
====
468468
In contrast to the supported return types for
469-
<<tests-sources-MethodSource, `@MethodSource`>> factory
469+
<<sources-MethodSource, `@MethodSource`>> factory
470470
methods, the value of a `@FieldSource` field cannot be an instance of `Stream`,
471471
`DoubleStream`, `LongStream`, `IntStream`, or `Iterator`, since the values of such types
472472
are _consumed_ the first time they are processed. However, if you wish to use one of
@@ -560,7 +560,7 @@ _fully qualified field name_ as demonstrated in the following example.
560560
include::example$java/example/ExternalFieldSourceDemo.java[tags=external_field_FieldSource_example]
561561
----
562562

563-
[[tests-sources-CsvSource]]
563+
[[sources-CsvSource]]
564564
=== @CsvSource
565565

566566
`@CsvSource` allows you to express argument lists as comma-separated values (i.e., CSV
@@ -683,7 +683,7 @@ within quoted strings, you will need to ensure that there is no leading whitespa
683683
your text block.
684684
====
685685

686-
[[tests-sources-CsvFileSource]]
686+
[[sources-CsvFileSource]]
687687
=== @CsvFileSource
688688

689689
`@CsvFileSource` lets you use comma-separated value (CSV) files from the classpath or the
@@ -750,7 +750,7 @@ Except within a quoted string, leading and trailing whitespace in a CSV column i
750750
by default. This behavior can be changed by setting the
751751
`ignoreLeadingAndTrailingWhitespace` attribute to `true`.
752752

753-
[[tests-sources-ArgumentsSource]]
753+
[[sources-ArgumentsSource]]
754754
=== @ArgumentsSource
755755

756756
`@ArgumentsSource` can be used to specify a custom, reusable `ArgumentsProvider`. Note
@@ -808,7 +808,7 @@ The following annotations are repeatable:
808808
* `@CsvFileSource`
809809
* `@ArgumentsSource`
810810

811-
[[tests-argument-count-validation]]
811+
[[argument-count-validation]]
812812
== Argument Count Validation
813813

814814
By default, when an arguments source provides more arguments than the test method needs,
@@ -831,10 +831,10 @@ use the `argumentCountValidation` attribute of the `@ParameterizedClass` or
831831
include::example$java/example/ParameterizedTestDemo.java[tags=argument_count_validation]
832832
----
833833

834-
[[tests-argument-conversion]]
834+
[[argument-conversion]]
835835
== Argument Conversion
836836

837-
[[tests-argument-conversion-widening]]
837+
[[argument-conversion-widening]]
838838
=== Widening Conversion
839839

840840
JUnit Jupiter supports
@@ -844,7 +844,7 @@ For example, a parameterized class or test method annotated with
844844
`@ValueSource(ints = { 1, 2, 3 })` can be declared to accept not only an argument of type
845845
`int` but also an argument of type `long`, `float`, or `double`.
846846

847-
[[tests-argument-conversion-implicit]]
847+
[[argument-conversion-implicit]]
848848
=== Implicit Conversion
849849

850850
To support use cases like `@CsvSource`, JUnit Jupiter provides a number of built-in
@@ -865,7 +865,7 @@ include::example$java/example/ParameterizedTestDemo.java[tags=implicit_conversio
865865
NOTE: Decimal, hexadecimal, and octal `String` literals will be converted to their
866866
integral types: `byte`, `short`, `int`, `long`, and their boxed counterparts.
867867

868-
[[tests-argument-conversion-implicit-table]]
868+
[[argument-conversion-implicit-table]]
869869
[cols="10,90"]
870870
|===
871871
| Target Type | Example
@@ -908,7 +908,7 @@ integral types: `byte`, `short`, `int`, `long`, and their boxed counterparts.
908908
| `java.util.UUID` | `"d043e930-7b3b-48e3-bdbe-5a3ccfb833db"` -> `UUID.fromString("d043e930-7b3b-48e3-bdbe-5a3ccfb833db")`
909909
|===
910910

911-
[[tests-argument-conversion-implicit-fallback]]
911+
[[argument-conversion-implicit-fallback]]
912912
==== Fallback String-to-Object Conversion
913913

914914
In addition to implicit conversion from strings to the target types listed in the above
@@ -950,7 +950,7 @@ include::example$java/example/ParameterizedTestDemo.java[tags=implicit_fallback_
950950
include::example$java/example/ParameterizedTestDemo.java[tags=implicit_fallback_conversion_example_Book]
951951
----
952952

953-
[[tests-argument-conversion-explicit]]
953+
[[argument-conversion-explicit]]
954954
=== Explicit Conversion
955955

956956
Instead of relying on implicit argument conversion, you may explicitly specify an
@@ -990,7 +990,7 @@ If you wish to implement a custom `ArgumentConverter` that also consumes an anno
990990
(like `JavaTimeArgumentConverter`), you have the possibility to extend the
991991
`{AnnotationBasedArgumentConverter}` class.
992992

993-
[[tests-argument-aggregation]]
993+
[[argument-aggregation]]
994994
== Argument Aggregation
995995

996996
By default, each _argument_ provided to a `@ParameterizedClass` or `@ParameterizedTest`
@@ -1001,7 +1001,7 @@ signatures, respectively.
10011001
In such cases, an `{ArgumentsAccessor}` can be used instead of multiple parameters. Using
10021002
this API, you can access the provided arguments through a single argument passed to your
10031003
test method. In addition, type conversion is supported as discussed in
1004-
<<tests-argument-conversion-implicit>>.
1004+
<<argument-conversion-implicit>>.
10051005

10061006
Besides, you can retrieve the current test invocation index with
10071007
`ArgumentsAccessor.getInvocationIndex()`.
@@ -1014,7 +1014,7 @@ include::example$java/example/ParameterizedTestDemo.java[tags=ArgumentsAccessor_
10141014
_An instance of `ArgumentsAccessor` is automatically injected into any parameter of type
10151015
`ArgumentsAccessor`._
10161016

1017-
[[tests-argument-aggregation-custom]]
1017+
[[argument-aggregation-custom]]
10181018
=== Custom Aggregators
10191019

10201020
Apart from direct access to the arguments of a `@ParameterizedClass` or
@@ -1055,7 +1055,7 @@ include::example$java/example/ParameterizedTestDemo.java[tags=ArgumentsAggregato
10551055
----
10561056

10571057

1058-
[[tests-display-names]]
1058+
[[display-names]]
10591059
== Customizing Display Names
10601060

10611061
By default, the display name of a parameterized class or test invocation contains the
@@ -1175,7 +1175,7 @@ Note that `argumentSet(String, Object...)` is a static factory method defined in
11751175
`org.junit.jupiter.params.provider.Arguments` interface.
11761176
====
11771177

1178-
[[tests-display-names-quoted-text]]
1178+
[[display-names-quoted-text]]
11791179
=== Quoted Text-based Arguments
11801180

11811181
As of JUnit Jupiter 6.0, text-based arguments in display names for parameterized tests are
@@ -1201,7 +1201,7 @@ in the display name would be `"'\\t'"` which is printed as `'\t'`.
12011201

12021202
For a concrete example, if you run the first `nullEmptyAndBlankStrings(String text)`
12031203
parameterized test method from the
1204-
<<tests-sources-null-and-empty>> section above, the following
1204+
<<sources-null-and-empty>> section above, the following
12051205
display names are generated.
12061206

12071207
----
@@ -1214,7 +1214,7 @@ display names are generated.
12141214
----
12151215

12161216
If you run the first `testWithCsvSource(String fruit, int rank)` parameterized test method
1217-
from the <<tests-sources-CsvSource>> section above, the
1217+
from the <<sources-CsvSource>> section above, the
12181218
following display names are generated.
12191219

12201220
----
@@ -1235,7 +1235,7 @@ instead of `3.14`. You can see the effect of this with the `rank` values in the
12351235
example.
12361236
====
12371237

1238-
[[tests-display-names-default-pattern]]
1238+
[[display-names-default-pattern]]
12391239
=== Default Display Name Pattern
12401240

12411241
If you'd like to set a default name pattern for all parameterized classes and tests in
@@ -1248,7 +1248,7 @@ xref:running-tests/configuration-parameters.adoc[] for other options).
12481248
junit.jupiter.params.displayname.default = {index}
12491249
----
12501250

1251-
[[tests-display-names-precedence-rules]]
1251+
[[display-names-precedence-rules]]
12521252
=== Precedence Rules
12531253

12541254
The display name for a parameterized class or test is determined according to the
@@ -1259,10 +1259,10 @@ following precedence rules:
12591259
3. `DEFAULT_DISPLAY_NAME` constant defined in
12601260
`org.junit.jupiter.params.ParameterizedInvocationConstants`
12611261

1262-
[[tests-lifecycle-interop]]
1262+
[[lifecycle-interop]]
12631263
== Lifecycle and Interoperability
12641264

1265-
[[tests-lifecycle-interop-methods]]
1265+
[[lifecycle-interop-methods]]
12661266
=== Parameterized Tests
12671267

12681268
Each invocation of a parameterized test has the same lifecycle as a regular `@Test`
@@ -1282,7 +1282,7 @@ lifecycle methods (e.g. `@BeforeEach`) and test class constructors.
12821282
include::example$java/example/ParameterizedTestDemo.java[tags=ParameterResolver_example]
12831283
----
12841284

1285-
[[tests-lifecycle-interop-classes]]
1285+
[[lifecycle-interop-classes]]
12861286
=== Parameterized Classes
12871287

12881288
Each invocation of a parameterized class has the same lifecycle as a regular test class.

documentation/modules/ROOT/partials/release-notes/release-notes-6.1.0-M2.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ easier to dynamically build arguments from collections when using
5656
** `Arguments.argumentSetFrom(String, Iterable<?>)`
5757
** `Arguments.toList()` — returns a mutable `List<@Nullable Object>`
5858
* Exclude competing `@Deprecated` factory methods in
59-
xref:writing-tests/parameterized-classes-and-tests.adoc#tests-argument-conversion-implicit-fallback[fallback String-to-Object]
59+
xref:writing-tests/parameterized-classes-and-tests.adoc#argument-conversion-implicit-fallback[fallback String-to-Object]
6060
converter.
6161
* Trim internal stack frames from `AssertionFailedError` stack traces.
6262
* Introduce new `trimStacktrace(Class<?>)` and `retainStackTraceElements(int)`

0 commit comments

Comments
 (0)