Skip to content

Commit 68c3445

Browse files
committed
Polish @timeout documentation in User Guide
1 parent 6679be8 commit 68c3445

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,9 +1614,9 @@ implementations.
16141614
WARNING: You're invited to give it a try and provide feedback to the JUnit team so they
16151615
can improve and eventually <<api-evolution, promote>> this feature.
16161616

1617-
The `@Timeout` annotation allows to declare that a test, test factory, test template, or
1618-
lifecycle method should fail if its execution time exceeds a given duration, and
1619-
optionally a time unit (seconds are used by default).
1617+
The `@Timeout` annotation allows one to declare that a test, test factory, test template,
1618+
or lifecycle method should fail if its execution time exceeds a given duration. The time
1619+
unit for the duration defaults to seconds but is configurable.
16201620

16211621
The following example shows how `@Timeout` is applied to lifecycle and test methods.
16221622

@@ -1628,23 +1628,23 @@ include::{testDir}/example/TimeoutDemo.java[tags=user_guide]
16281628
Contrary to the `assertTimeoutPreemptively()` assertion, the execution of the annotated
16291629
method proceeds in the main thread of the test. If the timeout is exceeded, the main
16301630
thread is interrupted from another thread. This is done to ensure interoperability with
1631-
frameworks such as Spring that make extensive use of mechanisms that are sensitive to the
1632-
currently running thread (e.g. `ThreadLocals`).
1631+
frameworks such as Spring that make use of mechanisms that are sensitive to the currently
1632+
running thread — for example, `ThreadLocal` transaction management.
16331633

1634-
To apply the same timeout to all test methods within a test class and all its `@Nested`
1635-
classes, you can declare the `@Timeout` annotation on the class level. It will then be
1634+
To apply the same timeout to all test methods within a test class and all of its `@Nested`
1635+
classes, you can declare the `@Timeout` annotation at the class level. It will then be
16361636
applied to all test, test factory, and test template methods within that class and its
1637-
`@Nested` classes unless overridden by a `@Timeout` annotation on a method or `@Nested`
1638-
class. Please note that `@Timeout` annotations declared on the class level are not
1639-
applied to lifecycle methods.
1637+
`@Nested` classes unless overridden by a `@Timeout` annotation on a specific method or
1638+
`@Nested` class. Please note that `@Timeout` annotations declared at the class level are
1639+
not applied to lifecycle methods.
16401640

1641-
Declaring `@Timeout` on a test factory method checks that the method returns within the
1642-
specified duration but does verify the execution time of the returned `DynamicTests`.
1643-
Please use `assertTimeout()`/`assertTimeoutPreemptively()` for that purpose.
1641+
Declaring `@Timeout` on a `@TestFactory` method checks that the factory method returns
1642+
within the specified duration but does verify the execution time of each individual
1643+
`DynamicTest` generated by the factory. Please use
1644+
`assertTimeout()` or `assertTimeoutPreemptively()` for that purpose.
16441645

1645-
If `@Timeout` is present on a test template method, such as a method annotated with
1646-
`@RepeatedTest` or `@ParameterizedTest`, each invocation is checked to finish within the
1647-
given timeout.
1646+
If `@Timeout` is present on a `@TestTemplate` method — for example, a `@RepeatedTest` or
1647+
`@ParameterizedTest` — each invocation will have the given timeout applied to it.
16481648

16491649
The following <<running-tests-config-params, configuration parameters>> can be used to
16501650
specify global timeouts for all methods of a certain category unless they or an enclosing

0 commit comments

Comments
 (0)