Class TestTemplateExtensionContext
- java.lang.Object
-
- org.junit.jupiter.engine.descriptor.AbstractExtensionContext<TestTemplateTestDescriptor>
-
- org.junit.jupiter.engine.descriptor.TestTemplateExtensionContext
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,ExtensionContext
final class TestTemplateExtensionContext extends AbstractExtensionContext<TestTemplateTestDescriptor>
- Since:
- 5.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
-
-
Field Summary
Fields Modifier and Type Field Description private TestInstances
testInstances
-
Constructor Summary
Constructors Constructor Description TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, TestInstances testInstances, ExecutableInvoker executableInvoker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.lang.reflect.AnnotatedElement>
getElement()
Get theAnnotatedElement
corresponding to the current extension context, if available.java.util.Optional<java.lang.Throwable>
getExecutionException()
Get the exception that was thrown during execution of the test or container associated with thisExtensionContext
, if available.protected Node.ExecutionMode
getPlatformExecutionMode()
java.util.Optional<java.lang.Class<?>>
getTestClass()
Get theClass
associated with the current test or container, if available.java.util.Optional<java.lang.Object>
getTestInstance()
Get the test instance associated with the current test or container, if available.java.util.Optional<TestInstance.Lifecycle>
getTestInstanceLifecycle()
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.java.util.Optional<TestInstances>
getTestInstances()
Get the test instances associated with the current test or container, if available.java.util.Optional<java.lang.reflect.Method>
getTestMethod()
Get theMethod
associated with the current test, if available.-
Methods inherited from class org.junit.jupiter.engine.descriptor.AbstractExtensionContext
close, getConfigurationParameter, getConfigurationParameter, getDisplayName, getExecutableInvoker, getExecutionMode, getParent, getRoot, getStore, getTags, getTestDescriptor, getUniqueId, publishReportEntry
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, publishReportEntry, publishReportEntry
-
-
-
-
Field Detail
-
testInstances
private final TestInstances testInstances
-
-
Constructor Detail
-
TestTemplateExtensionContext
TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, TestInstances testInstances, ExecutableInvoker executableInvoker)
-
-
Method Detail
-
getElement
public java.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
Description copied from interface:ExtensionContext
Get theAnnotatedElement
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
orMethod
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 theAnnotatedElement
; nevernull
but potentially empty - See Also:
ExtensionContext.getTestClass()
,ExtensionContext.getTestMethod()
-
getTestClass
public java.util.Optional<java.lang.Class<?>> getTestClass()
Description copied from interface:ExtensionContext
Get theClass
associated with the current test or container, if available.- Returns:
- an
Optional
containing the class; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestClass()
-
getTestInstanceLifecycle
public java.util.Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()
Description copied from interface:ExtensionContext
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instanceLifecycle
; nevernull
but potentially empty - See Also:
TestInstance
-
getTestInstance
public java.util.Optional<java.lang.Object> getTestInstance()
Description copied from interface:ExtensionContext
Get the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instance; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestInstance()
,ExtensionContext.getTestInstances()
-
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; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestInstances()
-
getTestMethod
public java.util.Optional<java.lang.reflect.Method> getTestMethod()
Description copied from interface:ExtensionContext
Get theMethod
associated with the current test, if available.- Returns:
- an
Optional
containing the method; nevernull
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 thisExtensionContext
, 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-levelExtension
. Similarly, if thisExtensionContext
represents a test class, the execution exception returned by this method can be any exception thrown in a@BeforeAll
orAfterAll
method or a class-levelExtension
.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; nevernull
but potentially empty if test execution has not (yet) resulted in an exception
-
getPlatformExecutionMode
protected Node.ExecutionMode getPlatformExecutionMode()
- Specified by:
getPlatformExecutionMode
in classAbstractExtensionContext<TestTemplateTestDescriptor>
-
-