55
55
* @author Sam Brannen
56
56
* @author Juergen Hoeller
57
57
* @since 2.5
58
+ * @see TestContextManager
58
59
* @see org.springframework.test.context.support.AbstractTestExecutionListener
59
60
*/
60
61
public interface TestExecutionListener {
@@ -70,6 +71,7 @@ public interface TestExecutionListener {
70
71
* concrete classes as necessary.
71
72
* @param testContext the test context for the test; never {@code null}
72
73
* @throws Exception allows any exception to propagate
74
+ * @since 3.0
73
75
*/
74
76
default void beforeTestClass (TestContext testContext ) throws Exception {
75
77
/* no-op */
@@ -90,34 +92,90 @@ default void prepareTestInstance(TestContext testContext) throws Exception {
90
92
}
91
93
92
94
/**
93
- * Pre-processes a test <em>before</em> execution of the
95
+ * Pre-processes a test <em>before</em> execution of <em>before</em>
96
+ * lifecycle callbacks of the underlying test framework — for example,
97
+ * by setting up test fixtures.
98
+ * <p>This method <strong>must</strong> be called immediately prior to
99
+ * framework-specific <em>before</em> lifecycle callbacks. For historical
100
+ * reasons, this method is named {@code beforeTestMethod}. Since the
101
+ * introduction of {@link #beforeTestExecution}, a more suitable name for
102
+ * this method might be something like {@code beforeTestSetUp} or
103
+ * {@code beforeEach}; however, it is unfortunately impossible to rename
104
+ * this method due to backward compatibility concerns.
105
+ * <p>The default implementation is <em>empty</em>. Can be overridden by
106
+ * concrete classes as necessary.
107
+ * @param testContext the test context in which the test method will be
108
+ * executed; never {@code null}
109
+ * @throws Exception allows any exception to propagate
110
+ * @see #afterTestMethod
111
+ * @see #beforeTestExecution
112
+ * @see #afterTestExecution
113
+ */
114
+ default void beforeTestMethod (TestContext testContext ) throws Exception {
115
+ /* no-op */
116
+ }
117
+
118
+ /**
119
+ * Pre-processes a test <em>immediately before</em> execution of the
94
120
* {@link java.lang.reflect.Method test method} in the supplied
95
- * {@link TestContext test context}, for example by setting up test
96
- * fixtures .
97
- * <p>This method should be called immediately prior to framework-specific
121
+ * {@link TestContext test context} — for example, for timing
122
+ * or logging purposes .
123
+ * <p>This method <strong>must</strong> be called after framework-specific
98
124
* <em>before</em> lifecycle callbacks.
99
125
* <p>The default implementation is <em>empty</em>. Can be overridden by
100
126
* concrete classes as necessary.
101
127
* @param testContext the test context in which the test method will be
102
128
* executed; never {@code null}
103
129
* @throws Exception allows any exception to propagate
130
+ * @since 5.0
131
+ * @see #beforeTestMethod
132
+ * @see #afterTestMethod
133
+ * @see #afterTestExecution
104
134
*/
105
- default void beforeTestMethod (TestContext testContext ) throws Exception {
135
+ default void beforeTestExecution (TestContext testContext ) throws Exception {
106
136
/* no-op */
107
137
}
108
138
109
139
/**
110
- * Post-processes a test <em>after</em> execution of the
140
+ * Post-processes a test <em>immediately after</em> execution of the
111
141
* {@link java.lang.reflect.Method test method} in the supplied
112
- * {@link TestContext test context}, for example by tearing down test
113
- * fixtures .
114
- * <p>This method should be called immediately after framework-specific
142
+ * {@link TestContext test context} — for example, for timing
143
+ * or logging purposes .
144
+ * <p>This method <strong>must</strong> be called before framework-specific
115
145
* <em>after</em> lifecycle callbacks.
116
146
* <p>The default implementation is <em>empty</em>. Can be overridden by
117
147
* concrete classes as necessary.
148
+ * @param testContext the test context in which the test method will be
149
+ * executed; never {@code null}
150
+ * @throws Exception allows any exception to propagate
151
+ * @since 5.0
152
+ * @see #beforeTestMethod
153
+ * @see #afterTestMethod
154
+ * @see #beforeTestExecution
155
+ */
156
+ default void afterTestExecution (TestContext testContext ) throws Exception {
157
+ /* no-op */
158
+ }
159
+
160
+ /**
161
+ * Post-processes a test <em>after</em> execution of <em>after</em>
162
+ * lifecycle callbacks of the underlying test framework — for example,
163
+ * by tearing down test fixtures.
164
+ * <p>This method <strong>must</strong> be called immediately after
165
+ * framework-specific <em>after</em> lifecycle callbacks. For historical
166
+ * reasons, this method is named {@code afterTestMethod}. Since the
167
+ * introduction of {@link #afterTestExecution}, a more suitable name for
168
+ * this method might be something like {@code afterTestTearDown} or
169
+ * {@code afterEach}; however, it is unfortunately impossible to rename
170
+ * this method due to backward compatibility concerns.
171
+ * <p>The default implementation is <em>empty</em>. Can be overridden by
172
+ * concrete classes as necessary.
118
173
* @param testContext the test context in which the test method was
119
174
* executed; never {@code null}
120
175
* @throws Exception allows any exception to propagate
176
+ * @see #beforeTestMethod
177
+ * @see #beforeTestExecution
178
+ * @see #afterTestExecution
121
179
*/
122
180
default void afterTestMethod (TestContext testContext ) throws Exception {
123
181
/* no-op */
@@ -134,6 +192,7 @@ default void afterTestMethod(TestContext testContext) throws Exception {
134
192
* concrete classes as necessary.
135
193
* @param testContext the test context for the test; never {@code null}
136
194
* @throws Exception allows any exception to propagate
195
+ * @since 3.0
137
196
*/
138
197
default void afterTestClass (TestContext testContext ) throws Exception {
139
198
/* no-op */
0 commit comments