Skip to content

Commit 7a2912c

Browse files
committed
Polishing
1 parent d46581c commit 7a2912c

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ In order to use parameterized classes or tests you need to add a dependency on t
7676
=== Parameterized Tests
7777

7878
Parameterized test methods _consume_ arguments directly from the configured source (see
79-
<<sources>>) following a one-to-one correlation between
80-
argument source index and method parameter index (see examples in
81-
<<sources-CsvSource>>). However, a parameterized test
79+
<<sources>>) following a one-to-one correlation between argument source index and method
80+
parameter index (see examples in <<sources-CsvSource>>). However, a parameterized test
8281
method may also choose to _aggregate_ arguments from the source into a single object
83-
passed to the method (see <<argument-aggregation>>).
84-
Additional arguments may also be provided by a `ParameterResolver` (e.g., to obtain an
85-
instance of `TestInfo`, `TestReporter`, etc.). Specifically, a parameterized test method
86-
must declare formal parameters according to the following rules.
82+
passed to the method (see <<argument-aggregation>>). Additional arguments may also be
83+
provided by a `ParameterResolver` — for example, to obtain an instance of `TestInfo`,
84+
`TestReporter`, and so forth. Specifically, a parameterized test method must declare
85+
formal parameters according to the following rules.
8786

8887
* Zero or more _indexed parameters_ must be declared first.
8988
* Zero or more _aggregators_ must be declared next.
@@ -363,16 +362,16 @@ with `@TestInstance(Lifecycle.PER_CLASS)`; whereas, factory methods in external
363362
must always be `static`.
364363

365364
Each factory method must generate a _stream_ of _arguments_, and each set of arguments
366-
within the stream will be provided as the physical arguments for individual invocations
367-
of the annotated `@ParameterizedClass` or `@ParameterizedTest`. Generally speaking this
365+
within the stream will be provided as the physical arguments for individual invocations of
366+
the annotated `@ParameterizedClass` or `@ParameterizedTest`. Generally speaking this
368367
translates to a `Stream` of `Arguments` (i.e., `Stream<Arguments>`); however, the actual
369368
concrete return type can take on many forms. In this context, a "stream" is anything that
370369
JUnit can reliably convert into a `Stream`, such as `Stream`, `DoubleStream`,
371370
`LongStream`, `IntStream`, `Collection`, `Iterator`, `Iterable`, an array of objects or
372371
primitives, or any type that provides an `iterator(): Iterator` method (such as, for
373372
example, a `kotlin.sequences.Sequence`). The "arguments" within the stream can be supplied
374-
as an instance of `Arguments`, an array of objects (e.g., `Object[]`), or a single value
375-
if the parameterized class or test method accepts a single argument.
373+
as an instance of `Arguments`, an array of objects (for example, `Object[]`), or a single
374+
value if the parameterized class or test method accepts a single argument.
376375

377376
If the return type is `Stream` or one of the primitive streams,
378377
JUnit will properly close it by calling `BaseStream.close()`,
@@ -432,7 +431,7 @@ factory method is referenced by its name since there is only one such method in
432431
class. If there are several local methods with the same name, parameters can also be
433432
provided to differentiate them – for example, `@MethodSource("factoryMethod()")` or
434433
`@MethodSource("factoryMethod(java.lang.String)")`. Alternatively, the factory method
435-
can be referenced by its fully qualified method name, e.g.
434+
can be referenced by its fully qualified method name — for example,
436435
`@MethodSource("example.MyTests#factoryMethod(java.lang.String)")`.
437436

438437
[source,java,indent=0]
@@ -881,7 +880,7 @@ integral types: `byte`, `short`, `int`, `long`, and their boxed counterparts.
881880
| `double`/`Double` | `"1.0"` -> `1.0d`
882881
| `Enum` subclass | `"SECONDS"` -> `TimeUnit.SECONDS`
883882
| `java.io.File` | `"/path/to/file"` -> `new File("/path/to/file")`
884-
| `java.lang.Class` | `"java.lang.Integer"` -> `java.lang.Integer.class` _(use `$` for nested classes, e.g. `"java.lang.Thread$State"`)_
883+
| `java.lang.Class` | `"java.lang.Integer"` -> `java.lang.Integer.class` _(use `$` for nested classes: `"java.lang.Thread$State"`)_
885884
| `java.lang.Class` | `"byte"` -> `byte.class` _(primitive types are supported)_
886885
| `java.lang.Class` | `"char[]"` -> `char[].class` _(array types are supported)_
887886
| `java.math.BigDecimal` | `"123.456e789"` -> `new BigDecimal("123.456e789")`
@@ -1200,9 +1199,8 @@ will be `"\"\\t\""` which is printed as `"\t"` instead of a blank string or invi
12001199
character. The same applies for a character argument `'\t'`, whose physical representation
12011200
in the display name would be `"'\\t'"` which is printed as `'\t'`.
12021201

1203-
For a concrete example, if you run the first `nullEmptyAndBlankStrings(String text)`
1204-
parameterized test method from the
1205-
<<sources-null-and-empty>> section above, the following
1202+
For a concrete example, if you run the first `nullValuesAndBlankStrings(String text)`
1203+
parameterized test method from the <<sources-null-and-empty>> section above, the following
12061204
display names are generated.
12071205

12081206
----
@@ -1215,8 +1213,7 @@ display names are generated.
12151213
----
12161214

12171215
If you run the first `testWithCsvSource(String fruit, int rank)` parameterized test method
1218-
from the <<sources-CsvSource>> section above, the
1219-
following display names are generated.
1216+
from the <<sources-CsvSource>> section above, the following display names are generated.
12201217

12211218
----
12221219
[1] fruit = "apple", rank = "1"
@@ -1276,7 +1273,7 @@ You may use `ParameterResolver` extensions with `@ParameterizedTest` methods. Ho
12761273
method parameters that are resolved by argument sources need to come first in the
12771274
parameter list. Since a test class may contain regular tests as well as parameterized
12781275
tests with different parameter lists, values from argument sources are not resolved for
1279-
lifecycle methods (e.g. `@BeforeEach`) and test class constructors.
1276+
lifecycle methods (for example, `@BeforeEach`) and test class constructors.
12801277

12811278
[source,java,indent=0]
12821279
----
@@ -1295,7 +1292,7 @@ IDE.
12951292
You may use `ParameterResolver` extensions with `@ParameterizedClass` constructors.
12961293
However, if constructor injection is used, constructor parameters that are resolved by
12971294
argument sources need to come first in the parameter list. Values from argument sources
1298-
are not resolved for regular lifecycle methods (e.g. `@BeforeEach`).
1295+
are not resolved for regular lifecycle methods (for example, `@BeforeEach`).
12991296

13001297
In addition to regular lifecycle methods, parameterized classes may declare
13011298
`{BeforeParameterizedClassInvocation}` and `{AfterParameterizedClassInvocation}` lifecycle

0 commit comments

Comments
 (0)