As of Spring Framework 3.2, the TestExecutionListener implementations ServletTestExecutionListenerDependencyInjectionTestExecutionListener, DirtiesContextTestExecutionListener, and TransactionalTestExecutionListener are automatically registered by default.
However, if a custom TestExecutionListener is registered via @TestExecutionListeners then the defaults will not be registered. In most common testing scenarios, this effectively forces the user to manually declare all default listeners in addition to any custom listeners, for example:
The problem with this approach is that it requires that the user know exactly which listeners are registered by default. Moreover, this set can change from release to release -- for example, ServletTestExecutionListener was added in release 3.2.
Provide a mechanism for instructing the TestContext framework to register all default TestExecutionListeners in addition to an explicitly configured custom TestExecutionListener.
This could be achieved via a new boolean flag in @TestExecutionListeners. Alternatively, an enum could be introduced that specifies how defaults should be handled -- for example, prepended to custom listeners, appended to customer listeners, or excluded (i.e., the current behavior).
If this proposal is not implemented, it should at least be clearly documented in both Javadoc and the reference manual that the defaults are not prepended by default when specifying a custom TestExecutionListener.
Affects: 3.0 GA
SEC-2587 Improvements in Spring Test ("is depended on by")
Prior to this commit, if a custom TestExecutionListener was registered
via @TestExecutionListeners the defaults would not be registered. Thus,
if a user wanted to declare a custom listener and use the default
listeners, the user was forced to manually declare all default
listeners in addition to any custom listeners. This unfortunately
required that the user know exactly which listeners were registered by
default. Moreover, the set of default listeners can change from release
to release, and with the support for automatic discovery of default
listeners introduced in #16092 it is no longer even possible to know
what the set of default TestExecutionListeners is before runtime.
This commit addresses this issue by introducing a mechanism for merging
custom declared listeners with the defaults for the current
environment. Specifically, @TestExecutionListeners supports a new
MergeMode that is used to control whether or not explicitly declared
listeners are merged with the default listeners when @TestExecutionListeners is declared on a class that does not inherit
listeners from a superclass.