Skip to content

Commit fca28bd

Browse files
committed
Cross-reference execution order sections in User Guide
Issue: #1620
1 parent d06c603 commit fca28bd

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

documentation/src/docs/asciidoc/user-guide/extensions.adoc

+25-19
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,13 @@ For a concrete example, consult the source code for the `{MockitoExtension}` and
320320
`{ParameterResolver}` defines the `Extension` API for dynamically resolving parameters at
321321
runtime.
322322

323-
If a test constructor or a `@Test`, `@RepeatedTest`, `@ParameterizedTest`,
324-
`@TestFactory`, `@BeforeEach`, `@AfterEach`, `@BeforeAll`, or `@AfterAll` method accepts
325-
a parameter, the parameter must be _resolved_ at runtime by a `ParameterResolver`. A
326-
`ParameterResolver` can either be built-in (see `{TestInfoParameterResolver}`) or
327-
<<extensions-registration,registered by the user>>. Generally speaking, parameters may be
328-
resolved by _name_, _type_, _annotation_, or any combination thereof. For concrete
329-
examples, consult the source code for `{CustomTypeParameterResolver}` and
330-
`{CustomAnnotationParameterResolver}`.
323+
If a _test class_ constructor, _test method_, or _lifecycle method_ (see
324+
<<writing-tests-classes-and-methods>>) accepts a parameter, the parameter must be
325+
_resolved_ at runtime by a `ParameterResolver`. A `ParameterResolver` can either be
326+
built-in (see `{TestInfoParameterResolver}`) or <<extensions-registration,registered by
327+
the user>>. Generally speaking, parameters may be resolved by _name_, _type_,
328+
_annotation_, or any combination thereof. For concrete examples, consult the source code
329+
for `{CustomTypeParameterResolver}` and `{CustomAnnotationParameterResolver}`.
331330

332331
[WARNING]
333332
====
@@ -358,8 +357,10 @@ information for the following events.
358357
* `testAborted`: invoked after a _test method_ has been aborted
359358
* `testFailed`: invoked after a _test method_ has failed
360359

361-
NOTE: In this context, _test method_ refers to any `@Test` method or `@TestTemplate`
362-
method (for example, a `@RepeatedTest` or `@ParameterizedTest`).
360+
NOTE: In contrast to the definition of "test method" presented in
361+
<<writing-tests-classes-and-methods>>, in this context _test method_ refers to any
362+
`@Test` method or `@TestTemplate` method (for example, a `@RepeatedTest` or
363+
`@ParameterizedTest`).
363364

364365
Extensions implementing this interface can be registered at the method level or at the
365366
class level. In the latter case they will be invoked for any contained _test method_
@@ -551,12 +552,15 @@ details.
551552
=== Relative Execution Order of User Code and Extensions
552553

553554
When executing a test class that contains one or more test methods, a number of extension
554-
callbacks are called in addition to the user-supplied test and lifecycle methods. The
555-
following diagram illustrates the relative order of user-supplied code and extension code.
555+
callbacks are called in addition to the user-supplied test and lifecycle methods.
556556

557+
NOTE: See also: <<writing-tests-test-execution-order>>
558+
559+
[[extensions-execution-order-overview]]
557560
==== User and Extension Code
558561

559-
User-supplied test and lifecycle methods are shown in orange, with callback code
562+
The following diagram illustrates the relative order of user-supplied code and extension
563+
code. User-supplied test and lifecycle methods are shown in orange, with callback code
560564
implemented by extensions shown in blue. The grey box denotes the execution of a single
561565
test method and will be repeated for every test method in the test class.
562566

@@ -627,7 +631,7 @@ steps are optional depending on the presence of user code or extension support f
627631
corresponding lifecycle callback. For further details on the various lifecycle callbacks
628632
please consult the respective Javadoc for each annotation and extension.
629633

630-
[[extensions-lifecycle-wrapping-behavior]]
634+
[[extensions-execution-order-wrapping-behavior]]
631635
==== Wrapping Behavior of Callbacks
632636

633637
JUnit Jupiter always guarantees _wrapping_ behavior for multiple registered extensions
@@ -644,8 +648,7 @@ callbacks implemented by `Extension2`. `Extension1` is therefore said to _wrap_
644648
`Extension2`.
645649

646650
JUnit Jupiter also guarantees _wrapping_ behavior within class and interface hierarchies
647-
for user-supplied lifecycle callbacks such as `@BeforeAll`, `@AfterAll`, `@BeforeEach`,
648-
and `@AfterEach` methods.
651+
for user-supplied _lifecycle methods_ (see <<writing-tests-classes-and-methods>>).
649652

650653
* `@BeforeAll` methods are inherited from superclasses as long as they are not _hidden_ or
651654
_overridden_. Furthermore, `@BeforeAll` methods from superclasses will be executed
@@ -786,7 +789,10 @@ See corresponding *.txt file in images folder for the source.
786789
////
787790
image::extensions_BrokenLifecycleMethodConfigDemo.png[caption='',title='BrokenLifecycleMethodConfigDemo']
788791

792+
[TIP]
793+
====
789794
Due to the aforementioned behavior, the JUnit Team recommends that developers declare at
790-
most one of each type of lifecycle method (i.e., `@BeforeAll`, `@AfterAll`, `@BeforeEach`,
791-
`@AfterEach`) per test class or test interface unless there are no dependencies between
792-
such lifecycle methods.
795+
most one of each type of _lifecycle method_ (see <<writing-tests-classes-and-methods>>)
796+
per test class or test interface unless there are no dependencies between such lifecycle
797+
methods.
798+
====

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ NOTE: Test classes, test methods, and lifecycle methods are not required to be `
118118
but they must _not_ be `private`.
119119

120120
The following test class demonstrates the use of `@Test` methods and all supported
121-
lifecycle methods.
121+
lifecycle methods. For further information on runtime semantics, see
122+
<<writing-tests-test-execution-order>> and
123+
<<extensions-execution-order-wrapping-behavior>>.
122124

123125
[source,java,indent=0]
124126
.A standard test class
@@ -459,9 +461,7 @@ By default, test methods will be ordered using an algorithm that is deterministi
459461
intentionally nonobvious. This ensures that subsequent runs of a test suite execute test
460462
methods in the same order, thereby allowing for repeatable builds.
461463

462-
NOTE: In this context, a _test method_ is any instance method that is directly annotated
463-
or meta-annotated with `@Test`, `@RepeatedTest`, `@ParameterizedTest`, `@TestFactory`, or
464-
`@TestTemplate`.
464+
NOTE: See <<writing-tests-classes-and-methods>> for a definition of _test method_.
465465

466466
Although true _unit tests_ typically should not rely on the order in which they are
467467
executed, there are times when it is necessary to enforce a specific test method execution
@@ -481,6 +481,8 @@ following built-in `MethodOrderer` implementations.
481481
* `{Random}`: orders test methods _pseudo-randomly_ and supports configuration of a custom
482482
_seed_.
483483

484+
NOTE: See also: <<extensions-execution-order-wrapping-behavior>>
485+
484486
The following example demonstrates how to guarantee that test methods are executed in the
485487
order specified via the `@Order` annotation.
486488

@@ -584,10 +586,9 @@ parameters. This allows for greater flexibility and enables _Dependency Injectio
584586
constructors and methods.
585587

586588
`{ParameterResolver}` defines the API for test extensions that wish to _dynamically_
587-
resolve parameters at runtime. If a test class constructor or a `@Test`, `@RepeatedTest`,
588-
`@ParameterizedTest`, `@TestFactory`, `@TestTemplate`, `@BeforeEach`, `@AfterEach`,
589-
`@BeforeAll`, or `@AfterAll` method accepts a parameter, the parameter must be resolved at
590-
runtime by a registered `ParameterResolver`.
589+
resolve parameters at runtime. If a _test class_ constructor, a _test method_, or a
590+
_lifecycle method_ (see <<writing-tests-classes-and-methods>>) accepts a parameter, the
591+
parameter must be resolved at runtime by a registered `ParameterResolver`.
591592

592593
There are currently three built-in resolvers that are registered automatically.
593594

0 commit comments

Comments
 (0)