Class ScreenshotExtension

java.lang.Object
io.klib.swtbot.jupiter.ScreenshotExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler, org.junit.jupiter.api.extension.TestExecutionExceptionHandler

public final class ScreenshotExtension extends Object implements org.junit.jupiter.api.extension.TestExecutionExceptionHandler, org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler
Jupiter 5/6 exception handler capturing test and lifecycle failures before rethrowing the same original throwable. Aborted tests are not captured. Register an instance with RegisterExtension; static registration covers class lifecycle failures. Requires a live application Display and shell; does not create UI or a test engine.
  • Constructor Details

    • ScreenshotExtension

      public ScreenshotExtension(Supplier<Screenshots> screenshots, Supplier<org.eclipse.swt.widgets.Shell> shell)
      Creates an extension using application-owned capture support.
      Parameters:
      screenshots - non-null supplier evaluated during failure handling; null result skips capture
      shell - non-null shell supplier evaluated on the application UI thread
      Throws:
      NullPointerException - if either supplier is null
  • Method Details

    • handleTestExecutionException

      public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable original) throws Throwable
      Captures a test-method failure, except an aborted test.
      Specified by:
      handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
      Parameters:
      context - current invocation identity
      original - original failure
      Throws:
      Throwable - the same original failure, with diagnostic problems suppressed
    • handleBeforeAllMethodExecutionException

      public void handleBeforeAllMethodExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable original) throws Throwable
      Captures a before-all failure, except an aborted test.
      Specified by:
      handleBeforeAllMethodExecutionException in interface org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler
      Parameters:
      context - current container identity
      original - original failure
      Throws:
      Throwable - the same original failure, with diagnostic problems suppressed
    • handleBeforeEachMethodExecutionException

      public void handleBeforeEachMethodExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable original) throws Throwable
      Captures a before-each failure, except an aborted test.
      Specified by:
      handleBeforeEachMethodExecutionException in interface org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler
      Parameters:
      context - current invocation identity
      original - original failure
      Throws:
      Throwable - the same original failure, with diagnostic problems suppressed
    • handleAfterEachMethodExecutionException

      public void handleAfterEachMethodExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable original) throws Throwable
      Captures an after-each failure if application UI remains available.
      Specified by:
      handleAfterEachMethodExecutionException in interface org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler
      Parameters:
      context - current invocation identity
      original - original failure
      Throws:
      Throwable - the same original failure; aborted tests are not captured
    • handleAfterAllMethodExecutionException

      public void handleAfterAllMethodExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable original) throws Throwable
      Captures an after-all failure if application UI remains available.
      Specified by:
      handleAfterAllMethodExecutionException in interface org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler
      Parameters:
      context - current container identity
      original - original failure
      Throws:
      Throwable - the same original failure; aborted tests are not captured