Class JupiterEngineExtensionContext

    • Method Detail

      • getElement

        public java.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
        Description copied from interface: ExtensionContext
        Get the AnnotatedElement corresponding to the current extension context, if available.

        For example, if the current extension context encapsulates a test class, test method, test factory method, or test template method, the annotated element will be the corresponding Class or Method reference.

        Favor this method over more specific methods whenever the AnnotatedElement API suits the task at hand — for example, when looking up annotations regardless of concrete element type.

        Returns:
        an Optional containing the AnnotatedElement; never null but potentially empty
        See Also:
        ExtensionContext.getTestClass(), ExtensionContext.getTestMethod()
      • getTestClass

        public java.util.Optional<java.lang.Class<?>> getTestClass()
        Description copied from interface: ExtensionContext
        Get the Class associated with the current test or container, if available.
        Returns:
        an Optional containing the class; never null but potentially empty
        See Also:
        ExtensionContext.getRequiredTestClass()
      • getTestInstances

        public java.util.Optional<TestInstances> getTestInstances()
        Description copied from interface: ExtensionContext
        Get the test instances associated with the current test or container, if available.

        While top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.

        Returns:
        an Optional containing the test instances; never null but potentially empty
        See Also:
        ExtensionContext.getRequiredTestInstances()
      • getTestMethod

        public java.util.Optional<java.lang.reflect.Method> getTestMethod()
        Description copied from interface: ExtensionContext
        Get the Method associated with the current test, if available.
        Returns:
        an Optional containing the method; never null but potentially empty
        See Also:
        ExtensionContext.getRequiredTestMethod()
      • getExecutionException

        public java.util.Optional<java.lang.Throwable> getExecutionException()
        Description copied from interface: ExtensionContext
        Get the exception that was thrown during execution of the test or container associated with this ExtensionContext, if available.

        This method is typically used for logging and tracing purposes. If you wish to actually handle an exception thrown during test execution, implement the TestExecutionExceptionHandler API.

        Unlike the exception passed to a TestExecutionExceptionHandler, an execution exception returned by this method can be any exception thrown during the invocation of a @Test method, its surrounding @BeforeEach and @AfterEach methods, or a test-level Extension. Similarly, if this ExtensionContext represents a test class, the execution exception returned by this method can be any exception thrown in a @BeforeAll or AfterAll method or a class-level Extension.

        Note, however, that this method will never return an exception swallowed by a TestExecutionExceptionHandler. Furthermore, if multiple exceptions have been thrown during test execution, the exception returned by this method will be the first such exception with all additional exceptions suppressed in the first one.

        Returns:
        an Optional containing the exception thrown; never null but potentially empty if test execution has not (yet) resulted in an exception