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
Improve Cartesian test documentation (#665 / #666)
`@CartesianTest.MethodFactory`-annotated methods can be non-static
under certain circumstances, but the demo snippets showed non-static
factory methods that didn't match these and were thus wrong. This
change fixes that, which required moving the factory methods from
non-static inner classes into the outer class. For conistency and to
make things easier in the future, the same was done for all other
snippets as well.
The snippets were prepended with imports, which was incoherent when
the snippets turned from classes to just methods. Hence the imports
were removed as well, which has the eadded benefit of not having to
maintain the imports and making the snippets shorter.
Closes: #665
PR: #666
@@ -27,23 +27,21 @@ NOTE: The CartesianTest extension has undergone significant changes in 1.6.0.
27
27
This included moving it into a new package.
28
28
link:/docs/cartesian-product-v1[The old variant] is deprecated and will be removed in the 2.0 release (tentatively scheduled for 2022).
29
29
30
-
== Basic Use
30
+
== Basic use
31
31
32
32
`@CartesianTest` is used _instead_ of `@Test` or other such annotations (e.g. `@RepeatedTest`).
33
33
34
34
You can supply test parameters to `@CartesianTest` in two ways:
35
35
36
-
- You can annotate your test method, providing all parameter values in a single annotation.
37
-
- The test parameters can be annotated with `@CartesianTest.Values`, `@CartesianTest.Enum`, or range source annotations (see <<Annotating your test parameters>>)
36
+
- You can annotate the test parameters directly with `@CartesianTest.Values`, `@CartesianTest.Enum`, or range source annotations (see <<Defining arguments on parameters>>)
37
+
- You can annotate test method itself with `@CartesianTest.MethodFactory` to point at a factory method that creates sets of arguments (see <<Defining arguments with factories>>)
38
38
39
39
Specifying more than one kind of parameter source (i.e.: annotating your test parameters and the test method itself) does not work and will throw an `ExtensionConfigurationException`.
40
40
41
41
Our earlier example with `{ 1, 2 }` and `{ 3, 4 }`, would look like this:
@@ -56,21 +54,14 @@ If your input is `{ 1, 1, 3 }` and `{ 2, 2 }` the extension will consider their
56
54
Otherwise, the test would run with the same parameters multiple times.
57
55
If you need to pass the same parameters multiple times, you might want to look into https://junit.org/junit5/docs/current/user-guide/#writing-tests-repeated-tests[repeated tests].
58
56
59
-
== Annotating your test parameters
57
+
== Defining arguments on parameters
60
58
61
59
You can annotate the parameters of your `@CartesianTest`, to provide values to that specific parameter.
62
60
Parameter annotations are "self-contained", they only provide values to the parameter they are on and do not interfere with each other.
63
61
You can mix and match parameter annotations as you need.
For more information, please see the link:docs/range-sources[separate documentation about range sources].
235
192
236
-
== Annotating your test method
193
+
== Defining arguments with factories
237
194
238
195
You can annotate your test method to supply arguments to all parameters simultaneously.
239
196
@@ -245,9 +202,9 @@ Just like with JUnit's `@MethodSource`, you can specify the factory method with
245
202
This method must return `ArgumentSets`.
246
203
247
204
`ArgumentSets` is a helper class, specifically for creating sets for `@CartesianTest`.
248
-
To create the test data, instantiate with the static factory method `argumentsForFirstParameter`, then call the `addValuesForNextParameter` method once per additional parameter in the order in which the they appear in the test method.
205
+
To create the test data, instantiate with the static factory method `argumentsForFirstParameter`, then call the `addValuesForNextParameter` method once per additional parameter in the order in which they appear in the test method.
249
206
In each call, pass in all values for the corresponding parameter.
250
-
For convenience, all methods return with your `ArgumentSets` instance, so you can chain `add()` calls.
207
+
For convenience, all methods return with your `ArgumentSets` instance, so you can chain `add...` calls.
251
208
If you want to create an initially-empty `ArgumentSets`, call the static factory method `create()`.
252
209
253
210
Let's look at an example.
@@ -288,11 +245,11 @@ You can reuse the same argument provider method multiple times.
0 commit comments