Top Fields Constructors Methods
org.junit.jupiter.engine.descriptor

pack-priv final Class TestTemplateExtensionContext

extends AbstractExtensionContext<TestTemplateTestDescriptor>
Class Inheritance
Imports
java.lang.reflect.AnnotatedElement, .Method, java.util.List, .Optional, org.jspecify.annotations.Nullable, org.junit.jupiter.api.TestInstance.Lifecycle, org.junit.jupiter.api.extension.ExtensionContext, .TestInstances, org.junit.jupiter.engine.config.JupiterConfiguration, org.junit.jupiter.engine.execution.LauncherStoreFacade, org.junit.jupiter.engine.extension.ExtensionRegistry, org.junit.platform.engine.EngineExecutionListener, org.junit.platform.engine.support.hierarchical.Node

Since
5.0

Field Summary

Modifier and TypeField and Description
private final @Nullable TestInstances

Constructor Summary

AccessConstructor and Description
pack-priv
TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, ExtensionRegistry extensionRegistry, LauncherStoreFacade launcherStoreFacade, @Nullable TestInstances testInstances)

Method Summary

Modifier and TypeMethod and Description
public Optional<AnnotatedElement>
getElement()

Implements org.junit.jupiter.api.extension.ExtensionContext.getElement.

Get the AnnotatedElement corresponding to the current extension context, if available.

public List<Class<?>>
getEnclosingTestClasses()

Implements org.junit.jupiter.api.extension.ExtensionContext.getEnclosingTestClasses.

Get the enclosing test classes of the current test or container.

public Optional<Throwable>
getExecutionException()

Implements org.junit.jupiter.api.extension.ExtensionContext.getExecutionException.

Get the exception that was thrown during execution of the test or container associated with this ExtensionContext, if available.

protected Node.ExecutionMode
public Optional<Class<?>>
getTestClass()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestClass.

Get the Class associated with the current test or container, if available.

public Optional<Object>
getTestInstance()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstance.

Get the test instance associated with the current test or container, if available.

public Optional<TestInstance.Lifecycle>
getTestInstanceLifecycle()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstanceLifecycle.

Get the Lifecycle of the test instance associated with the current test or container, if available.

public Optional<TestInstances>
getTestInstances()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstances.

Get the test instances associated with the current test or container, if available.

public Optional<Method>
getTestMethod()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestMethod.

Get the Method associated with the current test, if available.

Inherited from org.junit.jupiter.engine.descriptor.AbstractExtensionContext:
closegetConfigurationParametergetConfigurationParametergetDisplayNamegetExecutableInvokergetExecutionModegetExtensionsgetParentgetRootgetStoregetStoregetTagsgetTestDescriptorgetUniqueIdpublishDirectorypublishFilepublishReportEntry

Field Detail

testInstancesback to summary
private final @Nullable TestInstances testInstances

Constructor Detail

TestTemplateExtensionContextback to summary
pack-priv TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, ExtensionRegistry extensionRegistry, LauncherStoreFacade launcherStoreFacade, @Nullable TestInstances testInstances)

Method Detail

getElementback to summary
public Optional<AnnotatedElement> getElement()

Implements org.junit.jupiter.api.extension.ExtensionContext.getElement.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getElement.

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.

Annotations
@Override
getEnclosingTestClassesback to summary
public List<Class<?>> getEnclosingTestClasses()

Implements org.junit.jupiter.api.extension.ExtensionContext.getEnclosingTestClasses.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getEnclosingTestClasses.

Get the enclosing test classes of the current test or container.

This method is useful to look up annotations on nested test classes and their enclosing runtime types:

AnnotationSupport.findAnnotation(
    extensionContext.getRequiredTestClass(),
    MyAnnotation.class,
    extensionContext.getEnclosingTestClasses()
);
Annotations
@Override
getExecutionExceptionback to summary
public Optional<Throwable> getExecutionException()

Implements org.junit.jupiter.api.extension.ExtensionContext.getExecutionException.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getExecutionException.

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.

Annotations
@Override
getPlatformExecutionModeback to summary
protected Node.ExecutionMode getPlatformExecutionMode()

Implements abstract org.junit.jupiter.engine.descriptor.AbstractExtensionContext.getPlatformExecutionMode.

Annotations
@Override
getTestClassback to summary
public Optional<Class<?>> getTestClass()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestClass.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getTestClass.

Get the Class associated with the current test or container, if available.

Annotations
@Override
getTestInstanceback to summary
public Optional<Object> getTestInstance()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstance.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getTestInstance.

Get the test instance associated with the current test or container, if available.

Annotations
@Override
getTestInstanceLifecycleback to summary
public Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstanceLifecycle.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getTestInstanceLifecycle.

Get the Lifecycle of the test instance associated with the current test or container, if available.

Annotations
@Override
getTestInstancesback to summary
public Optional<TestInstances> getTestInstances()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestInstances.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getTestInstances.

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.

Annotations
@Override
getTestMethodback to summary
public Optional<Method> getTestMethod()

Implements org.junit.jupiter.api.extension.ExtensionContext.getTestMethod.

Doc from org.junit.jupiter.api.extension.ExtensionContext.getTestMethod.

Get the Method associated with the current test, if available.

Annotations
@Override