@@ -142,11 +142,20 @@ categories:
142
142
The `org.springframework.test.util` package contains several general purpose utilities
143
143
for use in unit and integration testing.
144
144
145
- `ReflectionTestUtils` is a collection of reflection-based utility methods. You can use
146
- these methods in testing scenarios where you need to change the value of a constant, set
147
- a non-`public` field, invoke a non-`public` setter method, or invoke a non-`public`
148
- configuration or lifecycle callback method when testing application code for use cases
149
- such as the following:
145
+ {api-spring-framework}/test/util/AopTestUtils.html[`AopTestUtils`] is a collection of
146
+ AOP-related utility methods. You can use these methods to obtain a reference to the
147
+ underlying target object hidden behind one or more Spring proxies. For example, if you
148
+ have configured a bean as a dynamic mock by using a library such as EasyMock or Mockito,
149
+ and the mock is wrapped in a Spring proxy, you may need direct access to the underlying
150
+ mock to configure expectations on it and perform verifications. For Spring's core AOP
151
+ utilities, see {api-spring-framework}/aop/support/AopUtils.html[`AopUtils`] and
152
+ {api-spring-framework}/aop/framework/AopProxyUtils.html[`AopProxyUtils`].
153
+
154
+ {api-spring-framework}/test/util/ReflectionTestUtils.html[`ReflectionTestUtils`] is a
155
+ collection of reflection-based utility methods. You can use these methods in testing
156
+ scenarios where you need to change the value of a constant, set a non-`public` field,
157
+ invoke a non-`public` setter method, or invoke a non-`public` configuration or lifecycle
158
+ callback method when testing application code for use cases such as the following:
150
159
151
160
* ORM frameworks (such as JPA and Hibernate) that condone `private` or `protected` field
152
161
access as opposed to `public` setter methods for properties in a domain entity.
@@ -156,14 +165,20 @@ such as the following:
156
165
* Use of annotations such as `@PostConstruct` and `@PreDestroy` for lifecycle callback
157
166
methods.
158
167
159
- {api-spring-framework}/test/util/AopTestUtils.html[`AopTestUtils`] is a collection of
160
- AOP-related utility methods. You can use these methods to obtain a reference to the
161
- underlying target object hidden behind one or more Spring proxies. For example, if you
162
- have configured a bean as a dynamic mock by using a library such as EasyMock or Mockito,
163
- and the mock is wrapped in a Spring proxy, you may need direct access to the underlying
164
- mock to configure expectations on it and perform verifications. For Spring's core AOP
165
- utilities, see {api-spring-framework}/aop/support/AopUtils.html[`AopUtils`] and
166
- {api-spring-framework}/aop/framework/AopProxyUtils.html[`AopProxyUtils`].
168
+ {api-spring-framework}/test/util/TestSocketUtils.html[`TestSocketUtils`] is a simple
169
+ utility for finding available TCP ports on `localhost` for use in integration testing
170
+ scenarios.
171
+
172
+ [NOTE]
173
+ ====
174
+ `TestSocketUtils` can be used in integration tests which start an external server on an
175
+ available random port. However, these utilities make no guarantee about the subsequent
176
+ availability of a given port and are therefore unreliable. Instead of using
177
+ `TestSocketUtils` to find an available local port for a server, it is recommended that
178
+ you rely on a server's ability to start on a random ephemeral port that it selects or is
179
+ assigned by the operating system. To interact with that server, you should query the
180
+ server for the port it is currently using.
181
+ ====
167
182
168
183
169
184
[[unit-testing-spring-mvc]]
0 commit comments