Skip to content

Commit cdf3132

Browse files
sbrannenmarcphilipp
authored andcommitted
Polish parameterized test support in user guide
Issue: #14
1 parent b591a04 commit cdf3132

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

documentation/src/docs/asciidoc/writing-tests.adoc

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ to the console.
526526
=== Parameterized Tests
527527

528528
Parameterized tests make it possible to run a test multiple times with different arguments. They are
529-
declared just like regular `@Test` methods, but use the `@ParameterizedTest` annotation instead. In
529+
declared just like regular `@Test` methods but use the `@ParameterizedTest` annotation instead. In
530530
addition, you must declare at least one _source_ that will provide the arguments for each
531531
invocation.
532532

@@ -551,15 +551,16 @@ testWithStringParameter(String) ✔
551551
[[writing-tests-parameterized-tests-setup]]
552552
==== Required Setup
553553

554-
In order to use parameterized tests you need to add a dependency to the `junit-jupiter-params`
554+
In order to use parameterized tests you need to add a dependency on the `junit-jupiter-params`
555555
artifact. Please refer to <<dependency-metadata>> for details.
556556

557557
[[writing-tests-parameterized-tests-sources]]
558558
==== Sources of Arguments
559559

560-
Out of the box, JUnit Jupiter already provides quite a few _source_ annotations. The following
561-
subsections provide a brief overview and an example for each of them. Please refer to the Javadoc in
562-
the `{params-provider-package}` package for additional information.
560+
Out of the box, JUnit Jupiter provides quite a few _source_ annotations. Each of the
561+
following subsections provides a brief overview and an example for each of them. Please
562+
refer to the JavaDoc in the `{params-provider-package}` package for additional
563+
information.
563564

564565
[[writing-tests-parameterized-tests-sources-ValueSource]]
565566
===== @ValueSource
@@ -592,7 +593,7 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=EnumSource_example]
592593

593594
`@MethodSource` allows to refer to one or multiple methods of the test class. Each method must
594595
return a `Stream`, an `Iterable`, an `Iterator`, or an array of arguments. In addition, each method
595-
must be `static` and don't use any parameters.
596+
must be `static` and must not accept any arguments.
596597

597598
If you only need a single parameter, you can return instances of the parameter type directly as
598599
demonstrated by the following example.
@@ -614,7 +615,8 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=multi_arg_MethodSourc
614615
[[writing-tests-parameterized-tests-sources-CsvSource]]
615616
===== @CsvSource
616617

617-
`@CsvSource` allows to express argument lists as comma-separated `String` literals.
618+
`@CsvSource` allows you to express argument lists as comma-separated values (i.e.,
619+
`String` literals).
618620

619621
[source,java,indent=0]
620622
[subs="verbatim"]
@@ -625,8 +627,8 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=CsvSource_example]
625627
[[writing-tests-parameterized-tests-sources-CsvFileSource]]
626628
===== @CsvFileSource
627629

628-
`@CsvFileSource` lets you use CSV files from the classpath. Each line leads to one invocation of the
629-
parameterized test.
630+
`@CsvFileSource` lets you use CSV files from the classpath. Each line from a CSV file
631+
results in one invocation of the parameterized test.
630632

631633
[source,java,indent=0]
632634
[subs="verbatim"]
@@ -660,11 +662,11 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsSource_examp
660662
===== Implicit Conversion
661663

662664
To support use cases like `@CsvSource`, JUnit Jupiter provides a number of built-in implicit
663-
conversions. The conversion process depends on the declared type of each method parameter.
665+
type converters. The conversion process depends on the declared type of each method parameter.
664666

665-
For example, if a `@ParameterizedTest` declares a parameter of type `TimeUnit` and the actual type
666-
supplied by the declared source is a `String`, it will automatically be converted into the
667-
corresponding enum constant.
667+
For example, if a `@ParameterizedTest` declares a parameter of type `TimeUnit` and the
668+
actual type supplied by the declared source is a `String`, the string will automatically
669+
be converted into the corresponding `TimeUnit` enum constant.
668670

669671
[source,java,indent=0]
670672
[subs="verbatim"]
@@ -725,17 +727,18 @@ include::{testDir}/example/ParameterizedTestDemo.java[tags=explicit_java_time_co
725727
[[writing-tests-parameterized-tests-display-names]]
726728
==== Customizing Display Names
727729

728-
By default, the display name of a parameterized test invocation containers the invocation index and
729-
the `String` representation of all arguments. You can customize the invocation display names by
730-
using the `name` parameter of the `@ParameterizedTest` annotation like in the following example.
730+
By default, the display name of a parameterized test invocation contains the invocation
731+
index and the `String` representation of all arguments for that specific invocation.
732+
However, you can customize invocation display names via the `name` attribute of the
733+
`@ParameterizedTest` annotation like in the following example.
731734

732735
[source,java,indent=0]
733736
[subs="verbatim"]
734737
----
735738
include::{testDir}/example/ParameterizedTestDemo.java[tags=custom_display_names]
736739
----
737740

738-
When executing this method using the `ConsoleLauncher` you will see output similar to the following.
741+
When executing the above method using the `ConsoleLauncher` you will see output similar to the following.
739742

740743
[source]
741744
[subs="verbatim"]
@@ -746,7 +749,7 @@ Display name of container ✔
746749
└─ 3 ==> first='baz, qux', second=3 ✔
747750
----
748751

749-
The following placeholders are available:
752+
The following placeholders are supported within custom display names.
750753

751754
[cols="20,80"]
752755
|===
@@ -761,10 +764,11 @@ The following placeholders are available:
761764
[[writing-tests-parameterized-tests-lifecycle-interop]]
762765
==== Lifecycle and Interoperability
763766

764-
Each invocation of a parameterized test has the same lifecycle as regular `@Test` methods. For
765-
example, `@BeforeEach` methods will be executed before each invocation. Similar to
766-
<<writing-tests-dynamic-tests>>, invocations will appear one by one in the test tree of an IDE. You
767-
may at will mix regular `@Test` methods and `@ParameterizedTest` methods within the same test class.
767+
Each invocation of a parameterized test has the same lifecycle as a regular `@Test`
768+
method. For example, `@BeforeEach` methods will be executed before each invocation.
769+
Similar to <<writing-tests-dynamic-tests>>, invocations will appear one by one in the
770+
test tree of an IDE. You may at will mix regular `@Test` methods and `@ParameterizedTest`
771+
methods within the same test class.
768772

769773
You may use `ParameterResolver` extensions with `@ParameterizedTest` methods. However, method
770774
parameters that are resolved by argument sources need to come first in the argument list.

0 commit comments

Comments
 (0)