Browse Source

Polishing

pull/34656/head
Sam Brannen 10 months ago
parent
commit
0fd94f1b9f
  1. 14
      framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc
  2. 7
      spring-test/src/main/java/org/springframework/test/context/TestExecutionListener.java

14
framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc

@ -7,16 +7,17 @@ by default, exactly in the following order:
* `ServletTestExecutionListener`: Configures Servlet API mocks for a * `ServletTestExecutionListener`: Configures Servlet API mocks for a
`WebApplicationContext`. `WebApplicationContext`.
* `DirtiesContextBeforeModesTestExecutionListener`: Handles the `@DirtiesContext` * `DirtiesContextBeforeModesTestExecutionListener`: Handles the `@DirtiesContext`
annotation for "`before`" modes. annotation for "before" modes.
* `ApplicationEventsTestExecutionListener`: Provides support for * `ApplicationEventsTestExecutionListener`: Provides support for
xref:testing/testcontext-framework/application-events.adoc[`ApplicationEvents`]. xref:testing/testcontext-framework/application-events.adoc[`ApplicationEvents`].
* `BeanOverrideTestExecutionListener`: Provides support for xref:testing/testcontext-framework/bean-overriding.adoc[] . * `BeanOverrideTestExecutionListener`: Provides support for
xref:testing/testcontext-framework/bean-overriding.adoc[].
* `DependencyInjectionTestExecutionListener`: Provides dependency injection for the test * `DependencyInjectionTestExecutionListener`: Provides dependency injection for the test
instance. instance.
* `MicrometerObservationRegistryTestExecutionListener`: Provides support for * `MicrometerObservationRegistryTestExecutionListener`: Provides support for
Micrometer's `ObservationRegistry`. Micrometer's `ObservationRegistry`.
* `DirtiesContextTestExecutionListener`: Handles the `@DirtiesContext` annotation for * `DirtiesContextTestExecutionListener`: Handles the `@DirtiesContext` annotation for
"`after`" modes. "after" modes.
* `CommonCachesTestExecutionListener`: Clears resource caches in the test's * `CommonCachesTestExecutionListener`: Clears resource caches in the test's
`ApplicationContext` if necessary. `ApplicationContext` if necessary.
* `TransactionalTestExecutionListener`: Provides transactional test execution with * `TransactionalTestExecutionListener`: Provides transactional test execution with
@ -161,15 +162,16 @@ change from release to release -- for example, `SqlScriptsTestExecutionListener`
introduced in Spring Framework 4.1, and `DirtiesContextBeforeModesTestExecutionListener` introduced in Spring Framework 4.1, and `DirtiesContextBeforeModesTestExecutionListener`
was introduced in Spring Framework 4.2. Furthermore, third-party frameworks like Spring was introduced in Spring Framework 4.2. Furthermore, third-party frameworks like Spring
Boot and Spring Security register their own default `TestExecutionListener` Boot and Spring Security register their own default `TestExecutionListener`
implementations by using the aforementioned xref:testing/testcontext-framework/tel-config.adoc#testcontext-tel-config-automatic-discovery[automatic discovery mechanism] implementations by using the aforementioned
. xref:testing/testcontext-framework/tel-config.adoc#testcontext-tel-config-automatic-discovery[automatic discovery mechanism].
To avoid having to be aware of and re-declare all default listeners, you can set the To avoid having to be aware of and re-declare all default listeners, you can set the
`mergeMode` attribute of `@TestExecutionListeners` to `MergeMode.MERGE_WITH_DEFAULTS`. `mergeMode` attribute of `@TestExecutionListeners` to `MergeMode.MERGE_WITH_DEFAULTS`.
`MERGE_WITH_DEFAULTS` indicates that locally declared listeners should be merged with the `MERGE_WITH_DEFAULTS` indicates that locally declared listeners should be merged with the
default listeners. The merging algorithm ensures that duplicates are removed from the default listeners. The merging algorithm ensures that duplicates are removed from the
list and that the resulting set of merged listeners is sorted according to the semantics list and that the resulting set of merged listeners is sorted according to the semantics
of `AnnotationAwareOrderComparator`, as described in xref:testing/testcontext-framework/tel-config.adoc#testcontext-tel-config-ordering[Ordering `TestExecutionListener` Implementations]. of `AnnotationAwareOrderComparator`, as described in
xref:testing/testcontext-framework/tel-config.adoc#testcontext-tel-config-ordering[Ordering `TestExecutionListener` Implementations].
If a listener implements `Ordered` or is annotated with `@Order`, it can influence the If a listener implements `Ordered` or is annotated with `@Order`, it can influence the
position in which it is merged with the defaults. Otherwise, locally declared listeners position in which it is merged with the defaults. Otherwise, locally declared listeners
are appended to the list of default listeners when merged. are appended to the list of default listeners when merged.

7
spring-test/src/main/java/org/springframework/test/context/TestExecutionListener.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,9 @@ package org.springframework.test.context;
* the listener is registered. * the listener is registered.
* *
* <p>Note that not all testing frameworks support all lifecycle callbacks defined * <p>Note that not all testing frameworks support all lifecycle callbacks defined
* in this API. For example, {@link #beforeTestExecution} and * in this API. For example, the {@link #beforeTestExecution(TestContext)
* {@link #afterTestExecution} are not supported in conjunction with JUnit 4 when * beforeTestExecution} and {@link #afterTestExecution(TestContext)
* afterTestExecution} callbacks are not supported in conjunction with JUnit 4 when
* using the {@link org.springframework.test.context.junit4.rules.SpringMethodRule * using the {@link org.springframework.test.context.junit4.rules.SpringMethodRule
* SpringMethodRule}. * SpringMethodRule}.
* *

Loading…
Cancel
Save