Module org.junit.platform.launcher
Package org.junit.platform.launcher
Interface LauncherInterceptor
-
@API(status=EXPERIMENTAL, since="1.10") public interface LauncherInterceptor
Interceptor for test discovery and execution by aLauncher
in the context of aLauncherSession
.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 totrue
.A typical use case is to create a custom
ClassLoader
in the constructor of the implementing class, replace thecontextClassLoader
of the current thread whileintercepting
invocations, and close the customClassLoader
inclose()
- Since:
- 1.10
- See Also:
Launcher
,LauncherSession
,LauncherConstants.ENABLE_LAUNCHER_INTERCEPTORS
-
creation of
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
LauncherInterceptor.Invocation<T>
An invocation that can be intercepted.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes this interceptor.<T> T
intercept(LauncherInterceptor.Invocation<T> invocation)
Intercept the supplied invocation.
-
-
-
Method Detail
-
intercept
<T> T intercept(LauncherInterceptor.Invocation<T> invocation)
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.
-
-