Module org.junit.platform.launcher
Package org.junit.platform.launcher
Interface LauncherInterceptor
Interceptor for test discovery and execution by a
Launcher
in the
context of a LauncherSession
.
Interceptors are instantiated once per LauncherSession
and closed
after the session is closed. They can
intercept the following invocations:
-
creation of
LauncherSessionListener
instances registered via theServiceLoader
mechanism -
creation of
Launcher
instances -
calls to
Launcher.discover(LauncherDiscoveryRequest)
,Launcher.execute(TestPlan, TestExecutionListener...)
, andLauncher.execute(LauncherDiscoveryRequest, TestExecutionListener...)
Implementations of this interface can be registered via the
ServiceLoader
mechanism by additionally
setting the "junit.platform.launcher.interceptors.enabled"
configuration parameter to true
.
A typical use case is to create a custom ClassLoader
in the
constructor of the implementing class, replace the
contextClassLoader
of the
current thread while intercepting
invocations,
and close the custom ClassLoader
in close()
- Since:
- 1.10
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
An invocation that can be intercepted. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this interceptor.<T> T
intercept
(LauncherInterceptor.Invocation<T> invocation) Intercept the supplied invocation.
-
Method Details
-
intercept
Intercept the supplied invocation.Implementations must call
LauncherInterceptor.Invocation.proceed()
exactly once.- Parameters:
invocation
- the intercepted invocation; nevernull
- Returns:
- the result of the invocation
-
close
void close()Closes this interceptor.Any resources held by this interceptor should be released by this method.
-