Interface LauncherInterceptor


@API(status=EXPERIMENTAL, since="1.10") public 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:

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

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    An invocation that can be intercepted.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this interceptor.
    <T> T
    Intercept the supplied invocation.
  • Method Details

    • 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; never null
      Returns:
      the result of the invocation
    • close

      void close()
      Closes this interceptor.

      Any resources held by this interceptor should be released by this method.