[[spring-testing-annotation-testexecutionlisteners]]
= `@TestExecutionListeners`

`@TestExecutionListeners` is used to register listeners for the annotated test class, its
subclasses, and its nested classes. If you wish to register a listener globally, you
should register it via the automatic discovery mechanism described in
xref:testing/testcontext-framework/tel-config.adoc[`TestExecutionListener` Configuration].

The following example shows how to register two `TestExecutionListener` implementations:

[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
	@ContextConfiguration
	@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class}) // <1>
	class CustomTestExecutionListenerTests {
		// class body...
	}
----
<1> Register two `TestExecutionListener` implementations.

Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
	@ContextConfiguration
	@TestExecutionListeners(CustomTestExecutionListener::class, AnotherTestExecutionListener::class) // <1>
	class CustomTestExecutionListenerTests {
		// class body...
	}
----
<1> Register two `TestExecutionListener` implementations.
======


By default, `@TestExecutionListeners` provides support for inheriting listeners from
superclasses or enclosing classes. See
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit-jupiter-nested-test-configuration[`@Nested` test class configuration]
and the {spring-framework-api}/test/context/TestExecutionListeners.html[`@TestExecutionListeners` javadoc]
for an example and further details. If you discover that you need to switch
back to using the default `TestExecutionListener` implementations, see the note in
xref:testing/testcontext-framework/tel-config.adoc#testcontext-tel-config-registering-tels[Registering `TestExecutionListener` Implementations].
