Skip to content

Commit bc417b4

Browse files
committed
Document test method execution order in Javadoc
Issue: #13
1 parent 4f90161 commit bc417b4

File tree

6 files changed

+115
-4
lines changed

6 files changed

+115
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ or meta-annotated with `@Test`, `@RepeatedTest`, `@ParameterizedTest`, `@TestFac
425425
Although true _unit tests_ typically should not rely on the order in which they are
426426
executed, there are times when it is necessary to enforce a specific test method execution
427427
order -- for example, when writing _integration tests_ or _functional tests_ where the
428-
sequence of the tests is important, especially in conjunction
428+
sequence of the tests is important, especially in conjunction with
429429
`@TestInstance(Lifecycle.PER_CLASS)`.
430430

431431
To control the order in which test methods are executed, annotate your test class or test

junit-jupiter-api/src/main/java/org/junit/jupiter/api/RepeatedTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@
4343
* create a custom <em>composed annotation</em> that inherits the semantics
4444
* of {@code @RepeatedTest}.
4545
*
46+
* <h3>Test Execution Order</h3>
47+
*
48+
* <p>By default, test methods will be ordered using an algorithm that is
49+
* deterministic but intentionally nonobvious. This ensures that subsequent runs
50+
* of a test suite execute test methods in the same order, thereby allowing for
51+
* repeatable builds. In this context, a <em>test method</em> is any instance
52+
* method that is directly annotated or meta-annotated with {@code @Test},
53+
* {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
54+
* {@code @TestTemplate}.
55+
*
56+
* <p>Although true <em>unit tests</em> typically should not rely on the order
57+
* in which they are executed, there are times when it is necessary to enforce
58+
* a specific test method execution order &mdash; for example, when writing
59+
* <em>integration tests</em> or <em>functional tests</em> where the sequence of
60+
* the tests is important, especially in conjunction with
61+
* {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
62+
*
63+
* <p>To control the order in which test methods are executed, annotate your
64+
* test class or test interface with {@link TestMethodOrder @TestMethodOrder}
65+
* and specify the desired {@link MethodOrderer} implementation.
66+
*
4667
* @since 5.0
4768
* @see DisplayName
4869
* @see RepetitionInfo

junit-jupiter-api/src/main/java/org/junit/jupiter/api/Test.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,36 @@
3232
* resolved by {@link org.junit.jupiter.api.extension.ParameterResolver
3333
* ParameterResolvers}.
3434
*
35-
* <p>{@code @Test} may also be used as a meta-annotation in order to
36-
* create a custom <em>composed annotation</em> that inherits the semantics
37-
* of {@code @Test}.
35+
* <p>{@code @Test} may also be used as a meta-annotation in order to create
36+
* a custom <em>composed annotation</em> that inherits the semantics of
37+
* {@code @Test}.
38+
*
39+
* <h3>Test Execution Order</h3>
40+
*
41+
* <p>By default, test methods will be ordered using an algorithm that is
42+
* deterministic but intentionally nonobvious. This ensures that subsequent runs
43+
* of a test suite execute test methods in the same order, thereby allowing for
44+
* repeatable builds. In this context, a <em>test method</em> is any instance
45+
* method that is directly annotated or meta-annotated with {@code @Test},
46+
* {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
47+
* {@code @TestTemplate}.
48+
*
49+
* <p>Although true <em>unit tests</em> typically should not rely on the order
50+
* in which they are executed, there are times when it is necessary to enforce
51+
* a specific test method execution order &mdash; for example, when writing
52+
* <em>integration tests</em> or <em>functional tests</em> where the sequence of
53+
* the tests is important, especially in conjunction with
54+
* {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
55+
*
56+
* <p>To control the order in which test methods are executed, annotate your
57+
* test class or test interface with {@link TestMethodOrder @TestMethodOrder}
58+
* and specify the desired {@link MethodOrderer} implementation.
3859
*
3960
* @since 5.0
61+
* @see RepeatedTest
62+
* @see org.junit.jupiter.params.ParameterizedTest
63+
* @see TestTemplate
64+
* @see TestFactory
4065
* @see TestInfo
4166
* @see DisplayName
4267
* @see Tag

junit-jupiter-api/src/main/java/org/junit/jupiter/api/TestFactory.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@
4343
* resolved by {@link org.junit.jupiter.api.extension.ParameterResolver
4444
* ParameterResolvers}.
4545
*
46+
* <h3>Test Execution Order</h3>
47+
*
48+
* <p>By default, test methods will be ordered using an algorithm that is
49+
* deterministic but intentionally nonobvious. This ensures that subsequent runs
50+
* of a test suite execute test methods in the same order, thereby allowing for
51+
* repeatable builds. In this context, a <em>test method</em> is any instance
52+
* method that is directly annotated or meta-annotated with {@code @Test},
53+
* {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
54+
* {@code @TestTemplate}.
55+
*
56+
* <p>Although true <em>unit tests</em> typically should not rely on the order
57+
* in which they are executed, there are times when it is necessary to enforce
58+
* a specific test method execution order &mdash; for example, when writing
59+
* <em>integration tests</em> or <em>functional tests</em> where the sequence of
60+
* the tests is important, especially in conjunction with
61+
* {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
62+
*
63+
* <p>To control the order in which test methods are executed, annotate your
64+
* test class or test interface with {@link TestMethodOrder @TestMethodOrder}
65+
* and specify the desired {@link MethodOrderer} implementation.
66+
*
4667
* @since 5.0
4768
* @see Test
4869
* @see DynamicNode

junit-jupiter-api/src/main/java/org/junit/jupiter/api/TestTemplate.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@
4949
* create a custom <em>composed annotation</em> that inherits the semantics
5050
* of {@code @TestTemplate}.
5151
*
52+
* <h3>Test Execution Order</h3>
53+
*
54+
* <p>By default, test methods will be ordered using an algorithm that is
55+
* deterministic but intentionally nonobvious. This ensures that subsequent runs
56+
* of a test suite execute test methods in the same order, thereby allowing for
57+
* repeatable builds. In this context, a <em>test method</em> is any instance
58+
* method that is directly annotated or meta-annotated with {@code @Test},
59+
* {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
60+
* {@code @TestTemplate}.
61+
*
62+
* <p>Although true <em>unit tests</em> typically should not rely on the order
63+
* in which they are executed, there are times when it is necessary to enforce
64+
* a specific test method execution order &mdash; for example, when writing
65+
* <em>integration tests</em> or <em>functional tests</em> where the sequence of
66+
* the tests is important, especially in conjunction with
67+
* {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
68+
*
69+
* <p>To control the order in which test methods are executed, annotate your
70+
* test class or test interface with {@link TestMethodOrder @TestMethodOrder}
71+
* and specify the desired {@link MethodOrderer} implementation.
72+
*
5273
* @since 5.0
5374
* @see Test
5475
* @see org.junit.jupiter.api.extension.TestTemplateInvocationContext

junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@
7979
* to create a custom <em>composed annotation</em> that inherits the semantics
8080
* of {@code @ParameterizedTest}.
8181
*
82+
* <h3>Test Execution Order</h3>
83+
*
84+
* <p>By default, test methods will be ordered using an algorithm that is
85+
* deterministic but intentionally nonobvious. This ensures that subsequent runs
86+
* of a test suite execute test methods in the same order, thereby allowing for
87+
* repeatable builds. In this context, a <em>test method</em> is any instance
88+
* method that is directly annotated or meta-annotated with {@code @Test},
89+
* {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
90+
* {@code @TestTemplate}.
91+
*
92+
* <p>Although true <em>unit tests</em> typically should not rely on the order
93+
* in which they are executed, there are times when it is necessary to enforce
94+
* a specific test method execution order &mdash; for example, when writing
95+
* <em>integration tests</em> or <em>functional tests</em> where the sequence of
96+
* the tests is important, especially in conjunction with
97+
* {@link org.junit.jupiter.api.TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
98+
*
99+
* <p>To control the order in which test methods are executed, annotate your
100+
* test class or test interface with
101+
* {@link org.junit.jupiter.api.TestMethodOrder @TestMethodOrder} and specify
102+
* the desired {@link org.junit.jupiter.api.MethodOrderer MethodOrderer}
103+
* implementation.
104+
*
82105
* @since 5.0
83106
* @see org.junit.jupiter.params.provider.Arguments
84107
* @see org.junit.jupiter.params.provider.ArgumentsProvider

0 commit comments

Comments
 (0)